Java Code Examples for org.apache.maven.plugin.logging.Log#debug()

The following examples show how to use org.apache.maven.plugin.logging.Log#debug() . 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: PomHelper.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Outputs a debug message with a list of modules.
 *
 * @param logger The logger to log to.
 * @param message The message to display.
 * @param modules The modules to append to the message.
 */
public static void debugModules( Log logger, String message, Collection modules )
{
    Iterator i;
    if ( logger.isDebugEnabled() )
    {
        logger.debug( message );
        if ( modules.isEmpty() )
        {
            logger.debug( "None." );
        }
        else
        {
            i = modules.iterator();
            while ( i.hasNext() )
            {
                logger.debug( "  " + i.next() );
            }
        }

    }
}
 
Example 2
Source File: DefaultSchemaCatalogSource.java    From cougar with Apache License 2.0 6 votes vote down vote up
@Override
public File getCatalog(File destDir, Log log) {

    // schemas
    for (String s : getSchemas()) {
        log.debug("Copying "+s+" to "+destDir);
        FileUtil.resourceToFile(s, new File(destDir, s), getClass());
    }

    // catalog (which works using relative links)
    File catalogFile = new File(destDir, getCatalogFileName());
    log.debug("Copying "+getCatalogFileName()+" to "+destDir);
    FileUtil.resourceToFile(getCatalogFileName(), catalogFile, getClass());

    return catalogFile;
}
 
Example 3
Source File: ProcessRunner.java    From botsing with Apache License 2.0 6 votes vote down vote up
private static void handleProcessOutput(final Process process, Log logger) {

		Thread reader = new Thread() {
			@Override
			public void run() {
				try {
					BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));

					while (!this.isInterrupted()) {
						String line = in.readLine();
						if (line != null && !line.isEmpty()) {
							logger.info(line);
						}
					}
				} catch (Exception e) {
					logger.debug("Exception while reading spawn process output: " + e.toString());
				}
			}
		};

		reader.start();
		logger.debug("Started thread to read spawn process output");
	}
 
Example 4
Source File: RequireEncoding.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
protected String getEncoding( String requiredEncoding, File file, Log log )
    throws IOException
{
    FileEncoding fileEncoding = new FileEncoding();
    if ( !fileEncoding.guessFileEncoding( Files.readAllBytes( file.toPath() ) ) )
    {
        return null;
    }

    if ( log.isDebugEnabled() )
    {
        log.debug( String.format( "%s: (%s) %s; charset=%s", file, fileEncoding.getCode(), fileEncoding.getType(), fileEncoding.getCodeMime() ) );
    }

    return fileEncoding.getCodeMime().toUpperCase();
}
 
Example 5
Source File: AwsAutoScalingDeployUtils.java    From vertx-deploy-tools with Apache License 2.0 5 votes vote down vote up
public List<Ec2Instance> getInstancesForAutoScalingGroup(Log log, AutoScalingGroup autoScalingGroup) throws MojoFailureException {
    log.info("retrieving list of instanceId's for auto scaling group with id : " + activeConfiguration.getAutoScalingGroupId());

    activeConfiguration.getHosts().clear();

    log.debug("describing instances in auto scaling group");

    if (autoScalingGroup.getInstances().isEmpty()) {
        return new ArrayList<>();
    }

    Map<String, Instance> instanceMap = autoScalingGroup.getInstances().stream().collect(Collectors.toMap(Instance::getInstanceId, Function.identity()));

    try {
        DescribeInstancesResult instancesResult = awsEc2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(autoScalingGroup.getInstances().stream().map(Instance::getInstanceId).collect(Collectors.toList())));
        List<Ec2Instance> ec2Instances = instancesResult.getReservations().stream().flatMap(r -> r.getInstances().stream()).map(this::toEc2Instance).collect(Collectors.toList());
        log.debug("describing elb status");
        autoScalingGroup.getLoadBalancerNames().forEach(elb -> this.updateInstancesStateOnLoadBalancer(elb, ec2Instances));
        ec2Instances.forEach(i -> i.updateAsState(AwsState.map(instanceMap.get(i.getInstanceId()).getLifecycleState())));
        ec2Instances.sort((o1, o2) -> {

            int sComp = o1.getAsState().compareTo(o2.getAsState());

            if (sComp != 0) {
                return sComp;
            } else {
                return o1.getElbState().compareTo(o2.getElbState());
            }
        });
        if (activeConfiguration.isIgnoreInStandby()) {
            return ec2Instances.stream().filter(i -> i.getAsState() != AwsState.STANDBY).collect(Collectors.toList());
        }
        return ec2Instances;
    } catch (AmazonClientException e) {
        log.error(e.getMessage(), e);
        throw new MojoFailureException(e.getMessage());
    }

}
 
Example 6
Source File: SpringBootUtil.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
/**
 * Read the value of the classifier configuration parameter from the
 * spring-boot-maven-plugin
 * 
 * @param project
 * @param log
 * @return the value if it was found, null otherwise
 */
public static String getSpringBootMavenPluginClassifier(MavenProject project, Log log) {
    String classifier = null;
    try {
        classifier = MavenProjectUtil.getPluginGoalConfigurationString(project,
                "org.springframework.boot:spring-boot-maven-plugin", "repackage", "classifier");
    } catch (PluginScenarioException e) {
        log.debug("No classifier found for spring-boot-maven-plugin");
    }
    return classifier;
}
 
Example 7
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Modifies the collection of child modules removing those which cannot be found relative to the parent.
 *
 * @param logger The logger to log to.
 * @param basedir the project basedir.
 * @param childModules the child modules.
 */
public static void removeMissingChildModules( Log logger, File basedir, Collection<String> childModules )
{
    logger.debug( "Removing child modules which are missing..." );
    Iterator<String> i = childModules.iterator();
    while ( i.hasNext() )
    {
        String modulePath = i.next();
        File moduleFile = new File( basedir, modulePath );

        if ( moduleFile.isDirectory() && new File( moduleFile, "pom.xml" ).isFile() )
        {
            // it's a directory that exists
            continue;
        }

        if ( moduleFile.isFile() )
        {
            // it's the pom.xml file directly referenced and it exists.
            continue;
        }

        logger.debug( "Removing missing child module " + modulePath );
        i.remove();
    }
    debugModules( logger, "After removing missing", childModules );
}
 
Example 8
Source File: AbstractDeployMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
/**
 * @param wagon
 * @param log
 */
private static void configureLog(Wagon wagon, Log log) {
    try {
        Method method = wagon.getClass().getMethod("setLog", Log.class);
        method.invoke(wagon, log);
        log.info("Set log for wagon: " + wagon);
    } catch (Exception e) {
        log.debug("Wagon does not supports setLog() method.");
    }
}
 
Example 9
Source File: ServiceUtils.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static Set<Artifact> filterArtifacts(Set<Artifact> artifacts, List<String> includes,
                                            List<String> excludes,
                                            boolean actTransitively, Log logger,
                                            ArtifactFilter... additionalFilters) {

    final AndArtifactFilter filter = new AndArtifactFilter();

    if (additionalFilters != null && additionalFilters.length > 0) {
        for (final ArtifactFilter additionalFilter : additionalFilters) {
            if (additionalFilter != null) {
                filter.add(additionalFilter);
            }
        }
    }

    if (!includes.isEmpty()) {
        final ArtifactFilter includeFilter = new PatternIncludesArtifactFilter(includes, actTransitively);
        filter.add(includeFilter);
    }

    if (!excludes.isEmpty()) {
        final ArtifactFilter excludeFilter = new PatternExcludesArtifactFilter(excludes, actTransitively);
        filter.add(excludeFilter);
    }

    Set<Artifact> copy = new LinkedHashSet<>(artifacts);
    for (final Iterator<Artifact> it = copy.iterator(); it.hasNext(); ) {

        final Artifact artifact = it.next();

        if (!filter.include(artifact)) {
            it.remove();
            if (logger.isDebugEnabled()) {
                logger.debug(artifact.getId() + " was removed by one or more filters.");
            }
        }
    }

    return copy;
}
 
Example 10
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the rule.
 *
 * @param helper the helper
 * @throws EnforcerRuleException the enforcer rule exception
 */
public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
{
    final Log log = helper.getLog();

    Object propValue = getPropertyValue( helper );
    checkPropValueNotBlank( propValue );

    final MavenProject project = getMavenProject( helper );
    log.debug( getRuleName() + ": checking property '" + property + "' for project " + project );

    final MavenProject parent = findDefiningParent( project );

    // fail fast if the defining parent could not be found due to a bug in the rule
    if ( parent == null )
    {
        throw new IllegalStateException( "Failed to find parent POM which defines the current rule" );
    }

    if ( project.equals( parent ) )
    {
        log.debug( getRuleName() + ": skip for property '" + property + "' as " + project + " defines rule." );
    }
    else
    {
        log.debug( "Check configuration defined in " + parent );
        if ( regex == null )
        {
            checkAgainstParentValue( project, parent, helper, propValue );
        }
        else
        {
            checkAgainstRegex( propValue );
        }
    }
}
 
Example 11
Source File: DefaultPomHelper.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<MavenProject> expandProjects ( final Collection<MavenProject> projects, final Log log, final MavenSession session )
{
    try
    {
        final Set<MavenProject> result = new HashSet<MavenProject> ();

        final Queue<MavenProject> queue = new LinkedList<MavenProject> ( projects );
        while ( !queue.isEmpty () )
        {
            final MavenProject project = queue.poll ();
            log.debug ( "Checking project: " + project );
            if ( project.getFile () == null )
            {
                log.info ( "Skipping non-local project: " + project );
                continue;
            }
            if ( !result.add ( project ) )
            {
                // if the project was already in our result, there is no need to process twice
                continue;
            }
            // add all children to the queue
            queue.addAll ( loadChildren ( project, log, session ) );
            if ( hasLocalParent ( project ) )
            {
                // if we have a parent, add the parent as well
                queue.add ( project.getParent () );
            }
        }
        return result;
    }
    catch ( final Exception e )
    {
        throw new RuntimeException ( e );
    }
}
 
Example 12
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void logInterfacesImplemented(Log log, JavaClass nextClass) {
    if (log.isDebugEnabled()) {
        final List<JavaClass> implementedInterfaces = getAllInterfacesQdox(nextClass);
        for (JavaClass implemented: implementedInterfaces) {
            log.debug("Interface implemented: " + implemented);
        }
    }
}
 
Example 13
Source File: ReportSourceLocator.java    From pitest with Apache License 2.0 5 votes vote down vote up
private File executeLocator(File reportsDirectory, Log log) {
  File[] subdirectories = reportsDirectory
      .listFiles(TIMESTAMPED_REPORTS_FILE_FILTER);
  File latest = reportsDirectory;

  log.debug("ReportSourceLocator starting search in directory ["
      + reportsDirectory.getAbsolutePath() + "]");

  if (subdirectories != null) {
    LastModifiedFileComparator c = new LastModifiedFileComparator();

    for (File f : subdirectories) {
      log.debug("comparing directory [" + f.getAbsolutePath()
          + "] with the current latest directory of ["
          + latest.getAbsolutePath() + "]");
      if (c.compare(latest, f) < 0) {
        latest = f;
        log.debug("directory [" + f.getAbsolutePath() + "] is now the latest");
      }
    }
  } else {
    throw new PitError("could not list files in directory ["
        + reportsDirectory.getAbsolutePath()
        + "] because of an unknown I/O error");
  }

  log.debug("ReportSourceLocator determined directory ["
      + latest.getAbsolutePath()
      + "] is the directory containing the latest pit reports");
  return latest;
}
 
Example 14
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of all child modules for a project, including any defined in profiles (ignoring profile
 * activation).
 *
 * @param model The project model.
 * @param logger The logger to use.
 * @return the set of all child modules of the project.
 */
public static Set<String> getAllChildModules( Model model, Log logger )
{
    logger.debug( "Finding child modules..." );
    Set<String> childModules = new TreeSet<String>();
    childModules.addAll( model.getModules() );
    for ( Profile profile : model.getProfiles() )
    {
        childModules.addAll( profile.getModules() );
    }
    debugModules( logger, "Child modules:", childModules );
    return childModules;
}
 
Example 15
Source File: CvsSVN.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
private boolean upToBranch(@Nonnull final Log logger, @Nullable final ProxySettings proxy, @Nullable final String customCommand, @Nonnull final File cvsFolder, @Nonnull final String branchId) {
    logger.debug("upToBranch : " + branchId);
    return checkResult(logger, execute(customCommand, logger, cvsFolder, "switch", "--accept", "theirs-full", "--force", branchId));
}
 
Example 16
Source File: ProcessRunner.java    From botsing with Apache License 2.0 4 votes vote down vote up
private static boolean executeProcess(File workDir, Log log, long timeout, String... command)
		throws InterruptedException, IOException {
	Process process = null;

	if (log.isDebugEnabled()) {
		log.debug("Going to execute command: " + String.join(" ", command));
	}

	try {
		ProcessBuilder builder = new ProcessBuilder(command);

		builder.directory(workDir.getAbsoluteFile());
		builder.redirectErrorStream(true);

		process = builder.start();
		handleProcessOutput(process, log);

		boolean exitResult = process.waitFor(timeout, TimeUnit.SECONDS);

		// process did not complete before timeout, kill it
		if (!exitResult) {
			log.error("Process terminated because it took more than " + timeout + "s to complete");
			throw new InterruptedException();
		}

		// Get process exitcode
		int exitCode = process.waitFor();

		if (exitCode != 0) {
			// process terminated abnormally
			log.error("Error executing process");
			return false;

		} else {
			// process terminated normally
			log.debug("Process terminated");
		}

	} catch (InterruptedException e) {
		if (process != null) {

			try {
				// be sure streamers are closed, otherwise process might
				// hang on Windows
				process.getOutputStream().close();
				process.getInputStream().close();
				process.getErrorStream().close();

			} catch (Exception t) {
				log.error("Failed to close process stream: " + t.toString());
			}

			process.destroy();

		}
		return false;

	}

	return true;
}
 
Example 17
Source File: SummaryBuilder.java    From maven-replacer-plugin with MIT License 4 votes vote down vote up
public void add(String inputFile, String outputFile, String encoding, Log log) {
	String encodingUsed = encoding == null ? "(default)" : encoding;
	log.debug(String.format(FILE_DEBUG_FORMAT, inputFile, outputFile, encodingUsed));
	filesReplaced++;
}
 
Example 18
Source File: RemovePluginsStep.java    From elasticsearch-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(InstanceConfiguration config)
{
    Log log = config.getClusterConfiguration().getLog();
    
    File pluginsDir = new File(config.getBaseDir(), "plugins");
    try
    {
        log.debug(String.format(
                "Checking if the plugins directory with path: '%s' exists",
                pluginsDir.getCanonicalPath()));
    }
    catch (IOException e)
    {
        throw new ElasticsearchSetupException(
                "Cannot check if the plugins directory exists",
                e);
    }

    if (pluginsDir.exists())
    {
        log.debug("The plugins directory exists; removing all installed plugins");

        if (VersionUtil.isEqualOrGreater_6_4_0(config.getClusterConfiguration().getVersion()))
        {
            FilesystemUtil.setScriptPermission(config, "elasticsearch-cli");
        }
        FilesystemUtil.setScriptPermission(config, "elasticsearch-plugin");

        CommandLine cmd = ProcessUtil.buildCommandLine("bin/elasticsearch-plugin")
                .addArgument("list");
        
        List<String> output = ProcessUtil.executeScript(config, cmd);
        // remove empty entries and trim
        List<String> pluginNames = output.stream()
                .map(String::trim)
                .filter(StringUtils::isNotEmpty)
                .collect(Collectors.toCollection(ArrayList::new));

        for (String pluginName : pluginNames)
        {
            log.info(String.format("Removing plugin '%s'", pluginName));
            
            CommandLine removeCmd = ProcessUtil.buildCommandLine("bin/elasticsearch-plugin")
                    .addArgument("remove")
                    .addArgument(pluginName);
            
            ProcessUtil.executeScript(config, removeCmd, config.getEnvironmentVariables(), null);
        }
    }
    else
    {
        log.debug("The plugins directory does not exist");
    }
}
 
Example 19
Source File: ArchiveEntryUtils.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void chmod(final File file, final int mode, final Log logger, boolean useJvmChmod) throws ArchiverException {
    if (!Os.isFamily(Os.FAMILY_UNIX)) {
        return;
    }

    final String m = Integer.toOctalString(mode & 0xfff);

    if (useJvmChmod && !jvmFilePermAvailable) {
        logger.info("chmod it's not possible where your current jvm");
        useJvmChmod = false;
    }

    if (useJvmChmod && jvmFilePermAvailable) {
        applyPermissionsWithJvm(file, m, logger);
        return;
    }

    try {
        final Commandline commandline = new Commandline();

        commandline.setWorkingDirectory(file.getParentFile().getAbsolutePath());

        if (logger.isDebugEnabled()) {
            logger.debug(file + ": mode " + Integer.toOctalString(mode) + ", chmod " + m);
        }

        commandline.setExecutable("chmod");

        commandline.createArg().setValue(m);

        final String path = file.getAbsolutePath();

        commandline.createArg().setValue(path);

        final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

        final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();

        final int exitCode = CommandLineUtils.executeCommandLine(commandline, stderr, stdout);

        if (exitCode != 0) {
            logger.warn("-------------------------------");
            logger.warn("Standard error:");
            logger.warn("-------------------------------");
            logger.warn(stderr.getOutput());
            logger.warn("-------------------------------");
            logger.warn("Standard output:");
            logger.warn("-------------------------------");
            logger.warn(stdout.getOutput());
            logger.warn("-------------------------------");

            throw new ArchiverException("chmod exit code was: " + exitCode);
        }
    } catch (final CommandLineException e) {
        throw new ArchiverException("Error while executing chmod.", e);
    }

}
 
Example 20
Source File: DocumentationUtils.java    From siddhi with Apache License 2.0 3 votes vote down vote up
/**
 * Executing a command.
 *
 * @param command The command to be executed
 * @param logger  The maven plugin logger
 * @throws Throwable if any error occurs during the execution of the command
 */
private static void executeCommand(String[] command, Log logger) throws Throwable {
    List<String> executionOutputLines = getCommandOutput(command, logger);
    for (String executionOutputLine : executionOutputLines) {
        logger.debug(executionOutputLine);
    }
}