org.sonatype.plexus.build.incremental.BuildContext Java Examples

The following examples show how to use org.sonatype.plexus.build.incremental.BuildContext. 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: PluginErrorListener.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
public static void logIError (@Nonnull final BuildContext aBuildContext,
                              @Nonnull final File aSourceFile,
                              @Nonnull final IError aResError)
{
  final int nLine = aResError.getErrorLocation ().getLineNumber ();
  final int nColumn = aResError.getErrorLocation ().getColumnNumber ();
  final String sMessage = StringHelper.getImplodedNonEmpty (" - ",
                                                            aResError.getErrorText (Locale.US),
                                                            aResError.getLinkedExceptionMessage ());

  // 0 means undefined line/column
  aBuildContext.addMessage (aSourceFile,
                            nLine <= 0 ? 0 : nLine,
                            nColumn <= 0 ? 0 : nColumn,
                            sMessage,
                            aResError.isError () ? BuildContext.SEVERITY_ERROR : BuildContext.SEVERITY_WARNING,
                            aResError.getLinkedExceptionCause ());
}
 
Example #2
Source File: MojoUtils.java    From frontend-maven-plugin with Apache License 2.0 6 votes vote down vote up
static boolean shouldExecute(BuildContext buildContext, List<File> triggerfiles, File srcdir) {

    // If there is no buildContext, or this is not an incremental build, always execute.
    if (buildContext == null || !buildContext.isIncremental()) {
      return true;
    }

    if (triggerfiles != null) {
      for (File triggerfile : triggerfiles) {
        if (buildContext.hasDelta(triggerfile)) {
          return true;
        }
      }
    }

    if (srcdir == null) {
      return true;
    }

    // Check for changes in the srcdir
    Scanner scanner = buildContext.newScanner(srcdir);
    scanner.scan();
    String[] includedFiles = scanner.getIncludedFiles();
    return (includedFiles != null && includedFiles.length > 0);
  }
 
Example #3
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Validate the version of the SARL library in the dependencies.
 *
 * <p>The test works for standard Java or Maven projects.
 *
 * <p>Caution: This function should not be called for Eclipse plugins.
 *
 * @throws CoreException if internal error occurs.
 */
protected void validateSARLLibraryVersion() throws CoreException {
	final Map<String, Artifact> artifacts = getMavenProjectFacade().getMavenProject().getArtifactMap();
	final Artifact artifact = artifacts.get(ArtifactUtils.versionlessKey(SARL_GROUP_ID, SARL_ARTIFACT_ID));
	if (artifact != null) {
		validateSARLVersion(SARL_GROUP_ID, SARL_ARTIFACT_ID, artifact.getVersion());
	} else {
		getBuildContext().addMessage(
				getMavenProjectFacade().getPomFile(),
				-1, -1,
				Messages.SARLProjectConfigurator_6,
				BuildContext.SEVERITY_ERROR,
				null);
	}
}
 
Example #4
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Validate the version of the SARL compiler in the Maven configuration.
 *
 * @return the SARL bundle.
 * @throws CoreException if internal error occurs.
 */
protected Bundle validateSARLCompilerPlugin() throws CoreException {
	final Map<String, Artifact> plugins = getMavenProjectFacade().getMavenProject().getPluginArtifactMap();
	final Artifact pluginArtifact = plugins.get(ArtifactUtils.versionlessKey(SARL_PLUGIN_GROUP_ID,
			SARL_PLUGIN_ARTIFACT_ID));
	if (pluginArtifact == null) {
		getBuildContext().addMessage(
				getMavenProjectFacade().getPomFile(),
				-1, -1,
				Messages.SARLProjectConfigurator_5,
				BuildContext.SEVERITY_ERROR,
				null);
	} else {
		final String version = pluginArtifact.getVersion();
		if (Strings.isNullOrEmpty(version)) {
			getBuildContext().addMessage(
					getMavenProjectFacade().getPomFile(),
					-1, -1,
					Messages.SARLProjectConfigurator_5,
					BuildContext.SEVERITY_ERROR,
					null);
		} else {
			return validateSARLVersion(
					SARL_PLUGIN_GROUP_ID, SARL_PLUGIN_ARTIFACT_ID,
					version);
		}
	}
	return null;
}
 
Example #5
Source File: IOUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Scans given directory for files satisfying given inclusion/exclusion
 * patterns.
 * 
 * @param buildContext
 *            Build context provided by the environment, used to scan for files.
 * @param directory
 *            Directory to scan.
 * @param includes
 *            inclusion pattern.
 * @param excludes
 *            exclusion pattern.
 * @param defaultExcludes
 *            default exclusion flag.
 * @return Files from the given directory which satisfy given patterns. The
 *         files are {@link File#getCanonicalFile() canonical}.
 * @throws IOException
 *             If an I/O error occurs, which is possible because the
 *             construction of the canonical pathname may require filesystem
 *             queries.
 */
public static List<File> scanDirectoryForFiles(BuildContext buildContext, final File directory,
		final String[] includes, final String[] excludes, boolean defaultExcludes) throws IOException {
	if (!directory.exists()) {
		return Collections.emptyList();
	}
	final Scanner scanner;

	if (buildContext != null) {
		scanner = buildContext.newScanner(directory, true);
	} else {
		final DirectoryScanner directoryScanner = new DirectoryScanner();
		directoryScanner.setBasedir(directory.getAbsoluteFile());
		scanner = directoryScanner;
	}
	scanner.setIncludes(includes);
	scanner.setExcludes(excludes);
	if (defaultExcludes) {
		scanner.addDefaultExcludes();
	}

	scanner.scan();

	final List<File> files = new ArrayList<File>();
	for (final String name : scanner.getIncludedFiles()) {
		files.add(new File(directory, name).getCanonicalFile());
	}

	return files;
}
 
Example #6
Source File: YangToSourcesProcessor.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private YangToSourcesProcessor(final BuildContext buildContext, final File yangFilesRootDir,
        final Collection<File> excludedFiles, final List<CodeGeneratorArg> codeGenerators,
        final MavenProject project, final boolean inspectDependencies, final YangProvider yangProvider) {
    this.buildContext = requireNonNull(buildContext, "buildContext");
    this.yangFilesRootDir = requireNonNull(yangFilesRootDir, "yangFilesRootDir");
    this.excludedFiles = ImmutableSet.copyOf(excludedFiles);
    this.codeGeneratorArgs = ImmutableList.copyOf(codeGenerators);
    this.project = requireNonNull(project);
    this.inspectDependencies = inspectDependencies;
    this.yangProvider = requireNonNull(yangProvider);
    this.parserFactory = DEFAULT_PARSER_FACTORY;
}
 
Example #7
Source File: CodeGenMojo.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public void setBuildContext(BuildContext buildContext) {
    this.buildContext = buildContext;
}
 
Example #8
Source File: RawXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void doExecute() throws MojoExecutionException {
	setupLogging();
	if (getVerbose())
		getLog().info("Started execution.");
	setupBindInfoPackage();
	setupEpisodePackage();
	setupMavenPaths();
	setupCatalogResolver();
	setupEntityResolver();
	setupSchemaFiles();
	setupBindingFiles();
	setupSchemas();
	setupBindings();
	setupDependsURIs();
	setupProducesURIs();
	setupURILastModifiedResolver();
	if (getVerbose()) {
		logConfiguration();
	}

	final OptionsConfiguration optionsConfiguration = createOptionsConfiguration();

	if (getVerbose()) {
		getLog().info("optionsConfiguration:" + optionsConfiguration);
	}

	checkCatalogsInStrictMode();

	if (getGrammars().isEmpty()) {
		getLog().warn("No schemas to compile. Skipping XJC execution. ");
	} else {

		final O options = getOptionsFactory().createOptions(optionsConfiguration);

		if (getForceRegenerate()) {
			getLog().warn("You are using forceRegenerate=true in your configuration.\n"
					+ "This configuration setting is deprecated and not recommended "
					+ "as it causes problems with incremental builds in IDEs.\n"
					+ "Please refer to the following link for more information:\n"
					+ "https://github.com/highsource/maven-jaxb2-plugin/wiki/Do-Not-Use-forceRegenerate\n"
					+ "Consider removing this setting from your plugin configuration.\n");
			getLog().info("The [forceRegenerate] switch is turned on, XJC will be executed.");
		} else {
			final boolean isUpToDate = isUpToDate();
			if (!isUpToDate) {
				getLog().info("Sources are not up-to-date, XJC will be executed.");
			} else {
				getLog().info("Sources are up-to-date, XJC will be skipped.");
				return;
			}
		}

		setupDirectories();
		doExecute(options);
		addIfExistsToEpisodeSchemaBindings();
		final BuildContext buildContext = getBuildContext();
		getLog().debug(MessageFormat.format("Refreshing the generated directory [{0}].",
				getGenerateDirectory().getAbsolutePath()));
		buildContext.refresh(getGenerateDirectory());
	}

	if (getVerbose()) {
		getLog().info("Finished execution.");
	}
}
 
Example #9
Source File: AbstractXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public BuildContext getBuildContext() {
	return buildContext;
}
 
Example #10
Source File: AbstractXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setBuildContext(BuildContext buildContext) {
	this.buildContext = buildContext;
}
 
Example #11
Source File: PluginErrorListener.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
public PluginErrorListener (@Nonnull final BuildContext aBuildContext, @Nonnull final File aSource)
{
  m_aBuildContext = aBuildContext;
  m_aSourceFile = aSource;
}
 
Example #12
Source File: YangToSourcesProcessor.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
YangToSourcesProcessor(final BuildContext buildContext, final File yangFilesRootDir,
            final Collection<File> excludedFiles, final List<CodeGeneratorArg> codeGenerators,
            final MavenProject project, final boolean inspectDependencies) {
    this(buildContext, yangFilesRootDir, excludedFiles, codeGenerators, project, inspectDependencies,
        YangProvider.getInstance());
}
 
Example #13
Source File: AsciidoctorFileScanner.java    From asciidoctor-maven-plugin with Apache License 2.0 4 votes vote down vote up
public AsciidoctorFileScanner(BuildContext buildContext) {
    this.buildContext = buildContext;
}
 
Example #14
Source File: AbstractJaxbMojo.java    From jaxb2-maven-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * The Plexus BuildContext is used to identify files or directories modified since last build,
 * implying functionality used to define if java generation must be performed again.
 *
 * @return the active Plexus BuildContext.
 */
protected final BuildContext getBuildContext() {
    return getInjectedObject(buildContext, "buildContext");
}
 
Example #15
Source File: BuildContextAware.java    From yangtools with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Set the build context to be used during the lifetime of this reactor.
 *
 * @param buildContext current build context reference.
 */
void setBuildContext(BuildContext buildContext);