org.codehaus.plexus.logging.Logger Java Examples

The following examples show how to use org.codehaus.plexus.logging.Logger. 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: CommandLineUtil.java    From maven-native with MIT License 6 votes vote down vote up
public static void execute( Commandline cl, Logger logger )
    throws NativeBuildException
{
    int ok;

    try
    {
        DefaultConsumer stdout = new DefaultConsumer();

        DefaultConsumer stderr = stdout;

        logger.info( cl.toString() );

        ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr );
    }
    catch ( CommandLineException ecx )
    {
        throw new NativeBuildException( "Error executing command line", ecx );
    }

    if ( ok != 0 )
    {
        throw new NativeBuildException( "Error executing command line. Exit code:" + ok );
    }
}
 
Example #2
Source File: YamlFileDependencyLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Dependency> load(Path filePath, Properties properties, Logger logger) throws LifecycleExecutionException {
    try {
        List<Dependency> dependencyList = new ArrayList<>();
        Yaml yaml = new Yaml();

        HashMap<String, List<Map<String, Object>>> root = yaml.load(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8)));
        if (root.containsKey("dependencies")) {
            for (Map<String, Object> coordinates : root.get("dependencies")) {
                Dependency dependency = new Dependency();
                dependency.setGroupId(Objects.toString(coordinates.get("groupId")));
                dependency.setArtifactId(Objects.toString(coordinates.get("artifactId")));
                dependency.setVersion(resolveVersionProperty(Objects.toString(coordinates.get("version")), properties));

                logger.info(String.format("Add %s", dependency));
                dependencyList.add(dependency);
            }
        }

        return dependencyList;
    } catch (IOException e) {
        throw new LifecycleExecutionException("Failed to read dependency configuration file", e);
    }
}
 
Example #3
Source File: FeatureTagsDependencyLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Load all dependencies specified through BDD tag information in given feature file content.
 * @param feature
 * @param properties
 * @param logger
 * @return
 */
private List<Dependency> loadDependencyTags(String feature, Properties properties, Logger logger) {
    return new BufferedReader(new StringReader(feature))
            .lines()
            .map(TAG_PATTERN::matcher)
            .filter(Matcher::matches)
            .map(matcher -> {
                try {
                    return build(matcher.group("coordinate"), properties, logger);
                } catch (LifecycleExecutionException e) {
                    logger.error("Failed to read dependency tag information", e);
                    return null;
                }
            })
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #4
Source File: EnvironmentSettingRepositoryLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
public List<Repository> load(Logger logger) throws LifecycleExecutionException {
    List<Repository> repositoryList = new ArrayList<>();

    String settings = getEnvSetting(ExtensionSettings.REPOSITORIES_SETTING_ENV);

    if (settings.length() > 0) {
        for (String scalar : settings.split(",")) {
            String[] config = scalar.split("=");
            if (config.length == 2) {
                repositoryList.add(build(config[0], config[1], logger));
            }
        }

        if (!repositoryList.isEmpty()) {
            logger.info(String.format("Add %s repositories found in environment variables", repositoryList.size()));
        }
    }

    return repositoryList;
}
 
Example #5
Source File: EnvironmentSettingDependencyLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
public List<Dependency> load(Properties properties, Logger logger) throws LifecycleExecutionException {
    List<Dependency> dependencyList = new ArrayList<>();

    String coordinates = getEnvSetting(ExtensionSettings.DEPENDENCIES_SETTING_ENV);

    if (coordinates.length() > 0) {
        for (String coordinate : coordinates.split(",")) {
            dependencyList.add(build(coordinate, properties, logger));
        }

        if (!dependencyList.isEmpty()) {
            logger.info(String.format("Add %s dependencies found in environment variables", dependencyList.size()));
        }
    }

    return dependencyList;
}
 
Example #6
Source File: JsonFileDependencyLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Dependency> load(Path filePath, Properties properties, Logger logger) throws LifecycleExecutionException {
    List<Dependency> dependencyList = new ArrayList<>();

    ObjectMapper mapper = new ObjectMapper();
    try {
        JsonNode root = mapper.readTree(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8)));
        ArrayNode dependencies = (ArrayNode) root.get("dependencies");
        for (Object o : dependencies) {
            ObjectNode coordinates = (ObjectNode) o;
            Dependency dependency = new Dependency();

            dependency.setGroupId(coordinates.get("groupId").textValue());
            dependency.setArtifactId(coordinates.get("artifactId").textValue());
            dependency.setVersion(resolveVersionProperty(coordinates.get("version").textValue(), properties));

            logger.info(String.format("Add %s", dependency));
            dependencyList.add(dependency);
        }
    } catch (IOException e) {
        throw new LifecycleExecutionException("Failed to read json dependency config file", e);
    }

    return dependencyList;
}
 
Example #7
Source File: SystemPropertyRepositoryLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
public List<Repository> load(Logger logger) throws LifecycleExecutionException {
    List<Repository> repositoryList = new ArrayList<>();

    String coordinates = System.getProperty(ExtensionSettings.REPOSITORIES_SETTING_KEY, "");

    if (coordinates.length() > 0) {
        for (String scalar : coordinates.split(",")) {
            String[] config = scalar.split("=");
            if (config.length == 2) {
                repositoryList.add(build(config[0], config[1], logger));
            }
        }

        if (!repositoryList.isEmpty()) {
            logger.info(String.format("Add %s repositories found in system properties", repositoryList.size()));
        }
    }

    return repositoryList;
}
 
Example #8
Source File: SystemPropertyDependencyLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Override
public List<Dependency> load(Properties properties, Logger logger) throws LifecycleExecutionException {
    List<Dependency> dependencyList = new ArrayList<>();

    String coordinates = System.getProperty(ExtensionSettings.DEPENDENCIES_SETTING_KEY, "");

    if (coordinates.length() > 0) {
        for (String coordinate : coordinates.split(",")) {
            dependencyList.add(build(coordinate, properties, logger));
        }

        if (!dependencyList.isEmpty()) {
            logger.info(String.format("Add %s dependencies found in system properties", dependencyList.size()));
        }
    }

    return dependencyList;
}
 
Example #9
Source File: TarGzArchive.java    From dropwizard-experiment with MIT License 6 votes vote down vote up
private static File tar(Set<File> files, String folder) throws IOException {
    TarArchiver tarArchive = new TarArchiver();
    tarArchive.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    for (File file : files) {
        // The starting ./ in the folder name is required for Heroku to be able to unpack the files correctly.
        if (file.isFile()) {
            tarArchive.addFile(file, "./" + folder + "/" + file.getName());
        } else if (file.isDirectory()) {
            tarArchive.addDirectory(file, "./" + folder + "/" + file.getName() + "/");
        }
    }

    File tarFile = File.createTempFile("TarGzArchive", ".tar");
    tarArchive.setDestFile(tarFile);
    tarArchive.createArchive();

    return tarFile;
}
 
Example #10
Source File: AbstractElasticsearchBaseMojo.java    From elasticsearch-maven-plugin with Apache License 2.0 6 votes vote down vote up
private int getMavenLogLevel()
{
    switch (logLevel)
    {
        case "DEBUG":
            return Logger.LEVEL_DEBUG;
        case "WARN":
            return Logger.LEVEL_WARN;
        case "ERROR":
            return Logger.LEVEL_ERROR;
        case "FATAL":
            return Logger.LEVEL_FATAL;
        case "DISABLED":
            return Logger.LEVEL_DISABLED;
        case "INFO":
        default:
            return Logger.LEVEL_INFO;
    }
}
 
Example #11
Source File: DetectExtension.java    From os-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Inject
public DetectExtension(final Logger logger) {
    this.logger = logger;
    detector = new Detector() {
        @Override
        protected void log(String message) {
            logger.info(message);
        }

        @Override
        protected void logProperty(String name, String value) {
            if (logger.isInfoEnabled()) {
                logger.info(name + ": " + value);
            }
        }
    };
}
 
Example #12
Source File: RepositoryLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Construct repository instance from given url. Query parameters are translated to fields on the target repository.
 * @param id
 * @param url
 * @param logger
 * @return
 */
default Repository build(String id, String url, Logger logger) throws LifecycleExecutionException {
    Repository repository = new Repository();

    repository.setId(id);

    try {
        URL configurationUrl = new URL(url);
        repository.setUrl(String.format("%s://%s%s", configurationUrl.getProtocol(), configurationUrl.getHost(), configurationUrl.getPath()));
    } catch (MalformedURLException e) {
        throw new LifecycleExecutionException("Failed to construct Maven repository model from given URL", e);
    }

    logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl()));
    return repository;
}
 
Example #13
Source File: DependencyLoader.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Construct dependency form coordinate string that follows the format "groupId:artifactId:version". Coordinates must
 * have a version set.
 * @param coordinates
 * @param properties
 * @param logger
 * @return
 */
default Dependency build(String coordinates, Properties properties, Logger logger) throws LifecycleExecutionException {
    Dependency dependency = new Dependency();
    Matcher matcher = COORDINATE_PATTERN.matcher(coordinates);
    if (!matcher.matches()) {
        throw new LifecycleExecutionException("Unsupported dependency coordinate. Must be of format groupId:artifactId:version");
    }

    String groupId = matcher.group("groupId");
    String artifactId = matcher.group("artifactId");
    String version = resolveVersionProperty(matcher.group("version"), properties);
    dependency.setGroupId(groupId);
    dependency.setArtifactId(artifactId);
    dependency.setVersion(version);

    logger.info(String.format("Add %s", dependency));
    return dependency;
}
 
Example #14
Source File: FileBasedRepositoryLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
public List<Repository> load(Logger logger) throws LifecycleExecutionException {
    Path settingsFile = getSettingsFile();

    if (Files.exists(settingsFile)) {
        Optional<String> fileExtension = getFileNameExtension(settingsFile.getFileName().toString());
        return fileExtension.flatMap(this::getFileConfigLoader)
                            .orElse(new PropertyFileRepositoryLoader())
                            .load(settingsFile, logger);
    }

    return Collections.emptyList();
}
 
Example #15
Source File: TarGzArchiveTest.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
private List<File> unpack(File tgzFile) {
    TarGZipUnArchiver unarchiver = new TarGZipUnArchiver(tgzFile);
    unarchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    unarchiver.setDestDirectory(unpackDir);
    unarchiver.extract();

    return ImmutableList.copyOf(unpackDir.listFiles());
}
 
Example #16
Source File: YamlFileRepositoryLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Repository> load(Path filePath, Logger logger) throws LifecycleExecutionException {
    try {
        List<Repository> repositoryList = new ArrayList<>();
        Yaml yaml = new Yaml();

        HashMap<String, List<Map<String, Object>>> root = yaml.load(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8)));
        if (root.containsKey("repositories")) {
            for (Map<String, Object> model : root.get("repositories")) {
                Repository repository = new Repository();

                repository.setId(Objects.toString(model.get("id")));
                repository.setName(Objects.toString(model.getOrDefault("name", repository.getId())));
                repository.setUrl(Objects.toString(model.get("url")));
                repository.setLayout(Objects.toString(model.getOrDefault("layout", "default")));

                if (model.containsKey("releases")) {
                    repository.setReleases(getRepositoryPolicy((Map<String, Object>) model.get("releases")));
                }

                if (model.containsKey("snapshots")) {
                    repository.setReleases(getRepositoryPolicy((Map<String, Object>) model.get("snapshots")));
                }

                logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl()));
                repositoryList.add(repository);
            }
        }

        return repositoryList;
    } catch (IOException e) {
        throw new LifecycleExecutionException("Failed to read repository configuration file", e);
    }
}
 
Example #17
Source File: FeatureTagsDependencyLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
public List<Dependency> load(Properties properties, Logger logger) throws LifecycleExecutionException {
    List<Dependency> dependencyList = new ArrayList<>();

    loadFromFileSystem(dependencyList, properties, logger);
    loadFromClasspath(dependencyList, properties, logger);

    return dependencyList;
}
 
Example #18
Source File: JsonFileRepositoryLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Repository> load(Path filePath, Logger logger) throws LifecycleExecutionException {
    List<Repository> repositoryList = new ArrayList<>();

    ObjectMapper mapper = new ObjectMapper();
    try {
        JsonNode root = mapper.readTree(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8)));
        ArrayNode repositories = (ArrayNode) root.get("repositories");
        for (Object o : repositories) {
            ObjectNode model = (ObjectNode) o;
            Repository repository = new Repository();

            repository.setId(model.get("id").textValue());
            repository.setUrl(model.get("url").textValue());

            if (model.get("name") != null) {
                repository.setName(model.get("name").textValue());
            }

            if (model.get("layout") != null) {
                repository.setLayout(model.get("layout").textValue());
            }

            if (model.get("releases") != null) {
                repository.setReleases(getRepositoryPolicy((ObjectNode) model.get("releases")));
            }

            if (model.get("snapshots") != null) {
                repository.setReleases(getRepositoryPolicy((ObjectNode) model.get("snapshots")));
            }

            logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl()));
            repositoryList.add(repository);
        }
    } catch (IOException e) {
        throw new LifecycleExecutionException("Failed to read json repository config file", e);
    }

    return repositoryList;
}
 
Example #19
Source File: FileBasedDependencyLoader.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Override
public List<Dependency> load(Properties properties, Logger logger) throws LifecycleExecutionException {
    Path settingsFile = getSettingsFile();

    if (Files.exists(settingsFile)) {
        Optional<String> fileExtension = getFileNameExtension(settingsFile.getFileName().toString());
        return fileExtension.flatMap(this::getFileConfigLoader)
                            .orElse(new PropertyFileDependencyLoader())
                            .load(settingsFile, properties, logger);
    }

    return Collections.emptyList();
}
 
Example #20
Source File: LoggerMessageWriter.java    From galleon with Apache License 2.0 5 votes vote down vote up
@Override
public void verbose(final Throwable cause, final CharSequence message) {
    final Logger logger = getLogger();
    if (logger.isDebugEnabled()) {
        if (message != null) {
            logger.debug(message.toString(), cause);
        } else {
            logger.debug(null, cause);
        }
    }
}
 
Example #21
Source File: JavaFXRunMojoTestCase.java    From javafx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private String execute(AbstractMojo mojo) throws MojoFailureException, MojoExecutionException, InterruptedException {
    PrintStream out = System.out;
    StringOutputStream stringOutputStream = new StringOutputStream();
    System.setOut(new PrintStream(stringOutputStream));
    mojo.setLog(new DefaultLog(new ConsoleLogger(Logger.LEVEL_ERROR, "javafx:run")));

    try {
        mojo.execute();
    } finally {
        Thread.sleep(300);
        System.setOut(out);
    }

    return stringOutputStream.toString();
}
 
Example #22
Source File: TarGzArchive.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
/**
 * Unpack a .tar.gz archive and return the folder it was unpacked in.
 *
 * @param tarGz The archive
 * @return The unpacked folder
 */
public static File unpack(File tarGz) {
    File unpackDir = Files.createTempDir();
    unpackDir.deleteOnExit();

    TarGZipUnArchiver unArchiver = new TarGZipUnArchiver(tarGz);
    // Needed to avoid a null pointer...
    unArchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    unArchiver.setDestDirectory(unpackDir);
    unArchiver.extract();

    return unpackDir;
}
 
Example #23
Source File: LoggerMessageWriter.java    From galleon with Apache License 2.0 5 votes vote down vote up
@Override
public void print(final Throwable cause, final CharSequence message) {
    final Logger logger = getLogger();
    if (logger.isInfoEnabled()) {
        if (message != null) {
            logger.info(message.toString(), cause);
        } else {
            logger.info(null, cause);
        }
    }
}
 
Example #24
Source File: LoggerMessageWriter.java    From galleon with Apache License 2.0 5 votes vote down vote up
@Override
public void error(final Throwable cause, final CharSequence message) {
    final Logger logger = getLogger();
    if (logger.isErrorEnabled()) {
        if (message != null) {
            logger.error(message.toString(), cause);
        } else {
            logger.error(null, cause);
        }
    }
}
 
Example #25
Source File: DefaultJnlpDependencyRequestConsumer.java    From webstart with MIT License 5 votes vote down vote up
private RequestTask( Logger logger, IOUtil ioUtil, JnlpDependencyRequest request )
{
    this.logger = logger;
    this.ioUtil = ioUtil;
    this.request = request;
    this.result = new JnlpDependencyResult( request );
}
 
Example #26
Source File: DefaultJnlpDependencyRequestConsumer.java    From webstart with MIT License 5 votes vote down vote up
public RequestExecutor( Logger logger, IOUtil ioUtil, JnlpDependencyRequestConsumerConfig config )
{
    super( config.getMaxThreads(), config.getMaxThreads(), 1L, TimeUnit.SECONDS,
           new LinkedBlockingQueue<Runnable>() );
    this.logger = logger;
    this.ioUtil = ioUtil;
    this.config = config;
    this.results = new JnlpDependencyResults();
}
 
Example #27
Source File: ScriptGeneratorBaseDirRepoTest.java    From appassembler with MIT License 5 votes vote down vote up
public void setUp()
    throws Exception
{
    super.setUp();

    LoggerManager loggerManager = (LoggerManager) lookup( LoggerManager.ROLE );

    loggerManager.setThreshold( Logger.LEVEL_DEBUG );
}
 
Example #28
Source File: ScriptGeneratorTest.java    From appassembler with MIT License 5 votes vote down vote up
public void setUp()
    throws Exception
{
    super.setUp();

    LoggerManager loggerManager = (LoggerManager) lookup( LoggerManager.ROLE );

    loggerManager.setThreshold( Logger.LEVEL_DEBUG );
}
 
Example #29
Source File: JdbcDataSourceTest.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
private JdbcDataSource newJdbcDataSource() {

        JdbcDataSource jdbcDataSource = new JdbcDataSource();
        JdbcDataSourceDescriptor descriptor = new JdbcDataSourceDescriptor();
        descriptor.setProperty("url", "jdbc:mysql://localhost:3306/test");
        descriptor.setProperty("driver", "com.mysql.jdbc.Driver");
        descriptor.setProperty("user", "root");
        descriptor.setProperty("password", "root");
//        descriptor.setProperty("checkout-timeout", "5000");
        jdbcDataSource.enableLogging(new NullLogger(Logger.LEVEL_DEBUG, getTestName()));
        jdbcDataSource.initialize(descriptor);

        return jdbcDataSource;
    }
 
Example #30
Source File: ScriptGeneratorBackgroundTest.java    From appassembler with MIT License 5 votes vote down vote up
public void setUp()
    throws Exception
{
    super.setUp();

    LoggerManager loggerManager = (LoggerManager) lookup( LoggerManager.ROLE );

    loggerManager.setThreshold( Logger.LEVEL_DEBUG );
}