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

The following examples show how to use org.apache.maven.plugin.logging.Log#isDebugEnabled() . 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: MavenVersionEnforcer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Compares the specified Maven version to see if it is allowed by the defined version range.
 *
 * @param log the log
 * @param requiredMavenVersionRange range of allowed versions for Maven.
 * @param actualMavenVersion the version to be checked.
 * @throws MojoExecutionException the given version fails the enforcement rule
 */
private void enforce(Log log,
        String requiredMavenVersionRange, ArtifactVersion actualMavenVersion)
        throws MojoExecutionException {
    if (StringUtils.isBlank(requiredMavenVersionRange)) {
        throw new MojoExecutionException("Maven version can't be empty.");
    }
    if (!actualMavenVersion.toString().equals(requiredMavenVersionRange)) {
        try {
            final VersionRange vr = VersionRange.createFromVersionSpec(requiredMavenVersionRange);
            if (!containsVersion(vr, actualMavenVersion)) {
                throw new MojoExecutionException(getDetectedVersionStr(actualMavenVersion.toString())
                        + " is not supported, it must be in " + vr + ".");
            }
        } catch (InvalidVersionSpecificationException e) {
            throw new MojoExecutionException("The requested Maven version "
                    + requiredMavenVersionRange + " is invalid.", e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(
                getDetectedVersionStr(actualMavenVersion.toString()) + " is allowed in " + requiredMavenVersionRange + ".");
    }
}
 
Example 2
Source File: FileSystemUtilities.java    From jaxb2-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static void checkAndAdd(final List<File> toPopulate,
                                final File current,
                                final List<Filter<File>> fileFilters,
                                final boolean excludeFilterOperation,
                                final Log log) {

    //
    // When no filters are supplied...
    // [Include Operation]: all files will be rejected
    // [Exclude Operation]: all files will be included
    //
    final boolean noFilters = fileFilters == null || fileFilters.isEmpty();
    final boolean addFile = excludeFilterOperation
            ? noFilters || Filters.rejectAtLeastOnce(current, fileFilters)
            : noFilters || Filters.matchAtLeastOnce(current, fileFilters);
    final String logPrefix = (addFile ? "Accepted " : "Rejected ")
            + (current.isDirectory() ? "directory" : "file") + " [";

    if (addFile) {
        toPopulate.add(current);
    }

    if (log.isDebugEnabled()) {
        log.debug(logPrefix + getCanonicalPath(current) + "]");
    }
}
 
Example 3
Source File: MavenLogHandler.java    From jaxb2-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the JUL Level matching the supplied Maven Log.
 *
 * @param mavenLog A non-null Maven Log.
 * @return The Corresponding JUL Level.
 */
public static Level getJavaUtilLoggingLevelFor(final Log mavenLog) {

    // Check sanity
    Validate.notNull(mavenLog, "mavenLog");

    Level toReturn = Level.SEVERE;

    if (mavenLog.isDebugEnabled()) {
        toReturn = Level.FINER;
    } else if (mavenLog.isInfoEnabled()) {
        toReturn = Level.INFO;
    } else if (mavenLog.isWarnEnabled()) {
        toReturn = Level.WARNING;
    }

    // All Done.
    return toReturn;
}
 
Example 4
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 5
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 6
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 7
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 8
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void logConstructor(Log log, Class<?> klass) {
    if (log.isDebugEnabled()) {
        try {
            log.debug("Constructor(empty): " + klass.getConstructor((Class<?>)null));
        } catch (SecurityException | NoSuchMethodException e) {
            log.debug("Cannot introspect empty constructor", e);
        }
    }
}
 
Example 9
Source File: AbstractFilter.java    From jaxb2-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void initialize(final Log log) {

    // Check sanity
    Validate.notNull(log, "log");

    // Assign internal state
    this.log = log;

    if (delayedLogMessages.size() > 0) {
        for (DelayedLogMessage current : delayedLogMessages) {
            if (current.logLevel.equalsIgnoreCase("warn") && log.isWarnEnabled()) {
                log.warn(current.message);
            } else if (current.logLevel.equals("info") && log.isInfoEnabled()) {
                log.info(current.message);
            } else if (log.isDebugEnabled()) {
                log.debug(current.message);
            }
        }

        delayedLogMessages.clear();
    }

    // Delegate
    onInitialize();
}
 
Example 10
Source File: AbstractRepo.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
public int execute(@Nullable String customCommand, @Nonnull final Log logger, @Nonnull final File cvsFolder, @Nonnull @MustNotContainNull final String... args) {
  final List<String> cli = new ArrayList<>();
  cli.add(GetUtils.findFirstNonNull(customCommand, this.command));
  cli.addAll(Arrays.asList(args));

  if (logger.isDebugEnabled()) {
    logger.debug("Executing repo command : " + cli);
  }

  final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
  final ByteArrayOutputStream outStream = new ByteArrayOutputStream();

  final ProcessExecutor executor = new ProcessExecutor(cli);

  int result = -1;

  try {
    final ProcessResult processResult = executor.directory(cvsFolder).redirectError(errorStream).redirectOutput(outStream).executeNoTimeout();
    result = processResult.getExitValue();

    if (logger.isDebugEnabled()) {
      logger.debug("Exec.out.........................................");
      logger.debug(new String(errorStream.toByteArray(), Charset.defaultCharset()));
      logger.debug(".................................................");
    }

    if (result != 0) {
      logger.error(new String(errorStream.toByteArray(), Charset.defaultCharset()));
    }

  } catch (IOException | InterruptedException | InvalidExitValueException ex) {
    if (ex instanceof InterruptedException) {
      Thread.currentThread().interrupt();
    }
    logger.error("Unexpected error", ex);
  }

  return result;
}
 
Example 11
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 12
Source File: MavenVersionEnforcer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void ensureMavenVersion(Log log, MavenSession session) throws MojoExecutionException {
    final String supported;
    try {
        supported = getSupportedMavenVersions();
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to ensure Quarkus Maven version compatibility", e);
    }
    String mavenVersion = session.getSystemProperties().getProperty("maven.version");
    if (log.isDebugEnabled()) {
        log.debug("Detected Maven Version: " + mavenVersion);
    }
    DefaultArtifactVersion detectedVersion = new DefaultArtifactVersion(mavenVersion);
    enforce(log, supported, detectedVersion);
}
 
Example 13
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void logProjectDependencies(MavenProject project, Log log) {
    log.debug("Logging project dependencies");
    if (log.isDebugEnabled()) {
        @SuppressWarnings("unchecked")
        final Set<Artifact> dependencies = project.getDependencyArtifacts();
        if (dependencies == null) {
            log.debug("No project dependencies");
        } else {
            for (Artifact artifact: dependencies) {
                log.debug("DEP: " + artifact);
            }
        }
    }
}
 
Example 14
Source File: RequireEncoding.java    From extra-enforcer-rules with Apache License 2.0 4 votes vote down vote up
public void execute( EnforcerRuleHelper helper )
    throws EnforcerRuleException
{
    try
    {
        if ( StringUtils.isBlank( encoding ) )
        {
            encoding = (String) helper.evaluate( "${project.build.sourceEncoding}" );
        }
        Log log = helper.getLog();

        Set< String > acceptedEncodings = new HashSet< String >( Arrays.asList( encoding ) );
        if ( encoding.equals( StandardCharsets.US_ASCII.name() ) )
        {
            log.warn( "Encoding US-ASCII is hard to detect. Use UTF-8 or ISO-8859-1" );
        }

        if ( acceptAsciiSubset && ( encoding.equals( StandardCharsets.ISO_8859_1.name() ) || encoding.equals( StandardCharsets.UTF_8.name() ) ) )
        {
            acceptedEncodings.add( StandardCharsets.US_ASCII.name() );
        }

        String basedir = (String) helper.evaluate( "${basedir}" );
        DirectoryScanner ds = new DirectoryScanner();
        ds.setBasedir( basedir );
        if ( StringUtils.isNotBlank( includes ) )
        {
            ds.setIncludes( includes.split( "[,\\|]" ) );
        }
        if ( StringUtils.isNotBlank( excludes ) )
        {
            ds.setExcludes( excludes.split( "[,\\|]" ) );
        }
        if ( useDefaultExcludes )
        {
            ds.addDefaultExcludes();
        }
        ds.scan();
        StringBuilder filesInMsg = new StringBuilder();
        for ( String file : ds.getIncludedFiles() )
        {
            String fileEncoding = getEncoding( encoding, new File( basedir, file ), log );
            if ( log.isDebugEnabled() )
            {
                log.debug( file + "==>" + fileEncoding );
            }
            if ( fileEncoding != null && !acceptedEncodings.contains( fileEncoding ) )
            {
                filesInMsg.append( file );
                filesInMsg.append( "==>" );
                filesInMsg.append( fileEncoding );
                filesInMsg.append( "\n" );
                if ( failFast )
                {
                    throw new EnforcerRuleException( filesInMsg.toString() );
                }
            }
        }
        if ( filesInMsg.length() > 0 )
        {
            throw new EnforcerRuleException( "Files not encoded in " + encoding + ":\n" + filesInMsg );
        }
    }
    catch ( IOException ex )
    {
        throw new EnforcerRuleException( "Reading Files", ex );
    }
    catch ( ExpressionEvaluationException e )
    {
        throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e );
    }
}
 
Example 15
Source File: PrepareFrontendMojo.java    From flow with Apache License 2.0 4 votes vote down vote up
private void propagateBuildInfo() {
    // For forked processes not accessing to System.properties we leave a
    // token file with the information about the build
    File token = new File(webpackOutputDirectory, TOKEN_FILE);
    JsonObject buildInfo = Json.createObject();
    buildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, productionMode);
    buildInfo.put(SERVLET_PARAMETER_USE_V14_BOOTSTRAP,
            useDeprecatedV14Bootstrapping());
    buildInfo.put(SERVLET_PARAMETER_INITIAL_UIDL, eagerServerLoad);
    buildInfo.put(NPM_TOKEN, npmFolder.getAbsolutePath());
    buildInfo.put(GENERATED_TOKEN, generatedFolder.getAbsolutePath());
    buildInfo.put(FRONTEND_TOKEN, frontendDirectory.getAbsolutePath());
    buildInfo.put(CONNECT_JAVA_SOURCE_FOLDER_TOKEN,
            javaSourceFolder.getAbsolutePath());
    buildInfo.put(CONNECT_APPLICATION_PROPERTIES_TOKEN,
            applicationProperties.getAbsolutePath());
    buildInfo.put(CONNECT_OPEN_API_FILE_TOKEN,
            openApiJsonFile.getAbsolutePath());
    buildInfo.put(CONNECT_GENERATED_TS_DIR_TOKEN,
            generatedTsFolder.getAbsolutePath());

    buildInfo.put(Constants.SERVLET_PARAMETER_ENABLE_PNPM, pnpmEnable);
    buildInfo.put(Constants.REQUIRE_HOME_NODE_EXECUTABLE,
            requireHomeNodeExec);

    try {
        FileUtils.forceMkdir(token.getParentFile());
        FileUtils.write(token, JsonUtil.stringify(buildInfo, 2) + "\n",
                StandardCharsets.UTF_8.name());

        // Inform m2eclipse that the directory containing the token file has
        // been updated in order to trigger server re-deployment (#6103)
        if (buildContext != null) {
            buildContext.refresh(token.getParentFile());
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }

    // Enable debug to find out problems related with flow modes
    Log log = getLog();
    if (log.isDebugEnabled()) {
        log.debug(String.format(
                "%n>>> Running prepare-frontend in %s project%nSystem"
                        + ".properties:%n productionMode: %s%n"
                        + " webpackPort: %s%n "
                        + "project.basedir: %s%nGoal parameters:%n "
                        + "productionMode: %s%n "
                        + "npmFolder: %s%nToken file: " + "%s%n"
                        + "Token content: %s%n",
                project.getName(),
                System.getProperty("vaadin.productionMode"),
                System.getProperty("vaadin.devmode.webpack.running-port"),
                System.getProperty("project.basedir"), productionMode,
                npmFolder, token.getAbsolutePath(), buildInfo.toJson()));
    }
}
 
Example 16
Source File: IDLReader.java    From cougar with Apache License 2.0 4 votes vote down vote up
public void init(
        Document iddDoc,
        Document extensionDoc,
        final String service,
        String packageName,
        final String basedir,
        final String genSrcDir,
        final Log log,
        final String outputDir,
        boolean client,
        boolean server)
        throws Exception {

    try {
        output = new File(basedir, genSrcDir);
        if (outputDir != null) {
            iDDOutputDir = new File(basedir+"/"+outputDir);
            if (!iDDOutputDir.exists()) {
                if (!iDDOutputDir.mkdirs()) {
                    throw new IllegalArgumentException("IDD Output Directory "+iDDOutputDir+" could not be created");
                }
            }
            if (!iDDOutputDir.isDirectory() || (!iDDOutputDir.canWrite())) {
                throw new IllegalArgumentException("IDD Output Directory "+iDDOutputDir+" is not a directory or cannot be written to.");
            }
        }
        config = new Configuration();
        config.setClassForTemplateLoading(IDLReader.class, "/templates");

        config.setStrictSyntaxMode(true);
        this.log = log;
        this.packageName = packageName;
        this.service = service;
        this.client = client;
        this.server = server || !client; // server must be true if client if false.

        dataModel = NodeModel.wrap(iddDoc.cloneNode(true));

        if (extensionDoc != null) {
            NodeModel extensionModel = NodeModel.wrap(extensionDoc);
            mergeExtensionsIntoDocument(getRootNode(dataModel),
                    getRootNode(extensionModel));
            removeUndefinedOperations(getRootNode(dataModel),
                    getRootNode(extensionModel));
        }
        if(log.isDebugEnabled()) {
            log.debug(serialize());
        }
    } catch (final Exception e) {
        log.error("Failed to initialise FTL", e);
        throw e;
    }
}
 
Example 17
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 4 votes vote down vote up
private void logDirectories(MavenProject project, Log log) {
    if (log.isDebugEnabled()) {
        log.debug("OutDir: " + project.getBuild().getOutputDirectory());
    }
}
 
Example 18
Source File: XsdGeneratorHelper.java    From jaxb2-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces all namespaces within generated schema files, as instructed by the configured Schema instances.
 *
 * @param resolverMap                The map relating generated schema file name to SimpleNamespaceResolver instances.
 * @param configuredTransformSchemas The Schema instances read from the configuration of this plugin.
 * @param mavenLog                   The active Log.
 * @param schemaDirectory            The directory where all generated schema files reside.
 * @param encoding                   The encoding to use when writing the file.
 * @throws MojoExecutionException If the namespace replacement could not be done.
 */
public static void replaceNamespacePrefixes(
        final Map<String, SimpleNamespaceResolver> resolverMap,
        final List<TransformSchema> configuredTransformSchemas,
        final Log mavenLog,
        final File schemaDirectory,
        final String encoding) throws MojoExecutionException {

    if (mavenLog.isDebugEnabled()) {
        mavenLog.debug("Got resolverMap.keySet() [generated filenames]: " + resolverMap.keySet());
    }

    for (SimpleNamespaceResolver currentResolver : resolverMap.values()) {
        File generatedSchemaFile = new File(schemaDirectory, currentResolver.getSourceFilename());
        Document generatedSchemaFileDocument = null;

        for (TransformSchema currentTransformSchema : configuredTransformSchemas) {
            // Should we alter the namespace prefix as instructed by the current schema?
            final String newPrefix = currentTransformSchema.getToPrefix();
            final String currentUri = currentTransformSchema.getUri();

            if (StringUtils.isNotEmpty(newPrefix)) {
                // Find the old/current prefix of the namespace for the current schema uri.
                final String oldPrefix = currentResolver.getNamespaceURI2PrefixMap().get(currentUri);

                if (StringUtils.isNotEmpty(oldPrefix)) {
                    // Can we perform the prefix substitution?
                    validatePrefixSubstitutionIsPossible(oldPrefix, newPrefix, currentResolver);

                    if (mavenLog.isDebugEnabled()) {
                        mavenLog.debug("Subtituting namespace prefix [" + oldPrefix + "] with [" + newPrefix
                                + "] in file [" + currentResolver.getSourceFilename() + "].");
                    }

                    // Get the Document of the current schema file.
                    if (generatedSchemaFileDocument == null) {
                        generatedSchemaFileDocument = parseXmlToDocument(generatedSchemaFile);
                    }

                    // Replace all namespace prefixes within the provided document.
                    process(generatedSchemaFileDocument.getFirstChild(), true,
                            new ChangeNamespacePrefixProcessor(oldPrefix, newPrefix));
                }
            }
        }

        if (generatedSchemaFileDocument != null) {
            // Overwrite the generatedSchemaFile with the content of the generatedSchemaFileDocument.
            mavenLog.debug("Overwriting file [" + currentResolver.getSourceFilename() + "] with content ["
                    + getHumanReadableXml(generatedSchemaFileDocument) + "]");
            savePrettyPrintedDocument(generatedSchemaFileDocument, generatedSchemaFile, encoding);
        } else {
            mavenLog.debug("No namespace prefix changes to generated schema file ["
                    + generatedSchemaFile.getName() + "]");
        }
    }
}
 
Example 19
Source File: AbstractJaxbMojo.java    From jaxb2-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {

    // 0) Get the log and its relevant level
    final Log log = getLog();
    final boolean isDebugEnabled = log.isDebugEnabled();
    final boolean isInfoEnabled = log.isInfoEnabled();

    // 1) Should we skip execution?
    if (shouldExecutionBeSkipped()) {

        if (isDebugEnabled) {
            log.debug("Skipping execution, as instructed.");
        }
        return;
    }

    // 2) Printout relevant version information.
    if (isDebugEnabled) {
        logPluginAndJaxbDependencyInfo();
    }

    // 3) Are generated files stale?
    if (isReGenerationRequired()) {

        if (performExecution()) {

            // As instructed by the performExecution() method, update
            // the timestamp of the stale File.
            updateStaleFileTimestamp();

            // Hack to support M2E
            buildContext.refresh(getOutputDirectory());

        } else if (isInfoEnabled) {
            log.info("Not updating staleFile timestamp as instructed.");
        }
    } else if (isInfoEnabled) {
        log.info("No changes detected in schema or binding files - skipping JAXB generation.");
    }

    // 4) If the output directories exist, add them to the MavenProject's source directories
    if (getOutputDirectory().exists() && getOutputDirectory().isDirectory()) {

        final String canonicalPathToOutputDirectory = FileSystemUtilities.getCanonicalPath(getOutputDirectory());

        if (log.isDebugEnabled()) {
            log.debug("Adding existing JAXB outputDirectory [" + canonicalPathToOutputDirectory
                    + "] to Maven's sources.");
        }

        // Add the output Directory.
        getProject().addCompileSourceRoot(canonicalPathToOutputDirectory);
    }
}
 
Example 20
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);
    }

}