org.apache.ivy.util.MessageLogger Java Examples

The following examples show how to use org.apache.ivy.util.MessageLogger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IvyContext.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public MessageLogger getMessageLogger() {
    // calling getIvy() instead of peekIvy() is not possible here: it will initialize a default
    // Ivy instance, with default settings, but settings themselves may log messages and lead to
    // a call to this method. So we use the current Ivy instance if any, or the default Ivy
    // instance, or the default MessageLogger.
    Ivy ivy = peekIvy();
    if (ivy == null) {
        if (defaultIvy == null) {
            return Message.getDefaultLogger();
        } else {
            return defaultIvy.getLoggerEngine();
        }
    } else {
        return ivy.getLoggerEngine();
    }
}
 
Example #2
Source File: MavenResolver.java    From IJava with MIT License 4 votes vote down vote up
public List<File> resolveMavenDependency(String canonical, Set<String> repos, int verbosity) throws IOException, ParseException {
    ChainResolver rootResolver = this.searchAllReposResolver(repos);

    Ivy ivy = this.createDefaultIvyInstance(verbosity);
    IvySettings settings = ivy.getSettings();

    settings.addResolver(rootResolver);
    rootResolver.setCheckmodified(true);
    settings.setDefaultResolver(rootResolver.getName());

    ivy.getLoggerEngine().info("Searching for dependencies in: " + rootResolver.getResolvers());

    ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setTransitive(true);
    resolveOptions.setDownload(true);

    ModuleRevisionId artifactIdentifier = MavenResolver.parseCanonicalArtifactName(canonical);
    DefaultModuleDescriptor containerModule = DefaultModuleDescriptor.newCallerInstance(
            artifactIdentifier,
            DEFAULT_RESOLVE_CONFS,
            true, // Transitive
            repos != null // Changing - the resolver will set this based on SNAPSHOT since they are all m2 compatible
            // but if `repos` is specified, we want to force a lookup.
    );

    ResolveReport resolved = ivy.resolve(containerModule, resolveOptions);
    if (resolved.hasError()) {
        MessageLogger logger = ivy.getLoggerEngine();
        Arrays.stream(resolved.getAllArtifactsReports())
                .forEach(r -> {
                    logger.error("download " + r.getDownloadStatus() + ": " + r.getArtifact() + " of " + r.getType());
                    if (r.getArtifactOrigin() == null)
                        logger.error("\tCouldn't find artifact.");
                    else
                        logger.error("\tfrom: " + r.getArtifactOrigin());
                });

        // TODO better error...
        throw new RuntimeException("Error resolving '" + canonical + "'. " + resolved.getAllProblemMessages());
    }

    return Arrays.stream(resolved.getAllArtifactsReports())
            .filter(a -> JAR_TYPE.equalsIgnoreCase(a.getType()))
            .map(ArtifactDownloadReport::getLocalFile)
            .collect(Collectors.toList());
}
 
Example #3
Source File: MavenResolver.java    From IJava with MIT License 4 votes vote down vote up
private File convertPomToIvy(Ivy ivy, File pomFile) throws IOException, ParseException {
    PomModuleDescriptorParser parser = PomModuleDescriptorParser.getInstance();

    URL pomUrl = pomFile.toURI().toURL();

    ModuleDescriptor pomModule = parser.parseDescriptor(new IvySettings(), pomFile.toURI().toURL(), false);

    File tempIvyFile = File.createTempFile("ijava-ivy-", ".xml").getAbsoluteFile();
    tempIvyFile.deleteOnExit();

    parser.toIvyFile(pomUrl.openStream(), new URLResource(pomUrl), tempIvyFile, pomModule);

    MessageLogger logger = ivy.getLoggerEngine();
    logger.info(new String(Files.readAllBytes(tempIvyFile.toPath()), Charset.forName("utf8")));

    return tempIvyFile;
}
 
Example #4
Source File: MavenResolver.java    From IJava with MIT License 3 votes vote down vote up
/**
 * Create an ivy instance with the specified verbosity. The instance is relatively plain.
 *
 * @param verbosity the verbosity level.
 *                  <ol start="0">
 *                  <li>ERROR</li>
 *                  <li>WANRING</li>
 *                  <li>INFO</li>
 *                  <li>VERBOSE</li>
 *                  <li>DEBUG</li>
 *                  </ol>
 *
 * @return the fresh ivy instance.
 */
private Ivy createDefaultIvyInstance(int verbosity) {
    MessageLogger logger = new DefaultMessageLogger(verbosity);

    // Set the default logger since not all things log to the ivy instance.
    Message.setDefaultLogger(logger);
    Ivy ivy = new Ivy();

    ivy.getLoggerEngine().setDefaultLogger(logger);
    ivy.setSettings(new IvySettings());
    ivy.bind();

    return ivy;
}