org.apache.maven.project.MavenProjectHelper Java Examples

The following examples show how to use org.apache.maven.project.MavenProjectHelper. 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: WebJarPackagerTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultPackaging() throws MojoExecutionException, IOException {
    WebJarPackager packager = new WebJarPackager();
    packager.project = mock(MavenProject.class);
    packager.projectHelper = mock(MavenProjectHelper.class);
    when(packager.project.getArtifactId()).thenReturn("test");
    when(packager.project.getVersion()).thenReturn("1.1");
    when(packager.project.getBasedir()).thenReturn(fake);
    packager.buildDirectory = new File("target/junk");
    copy();
    packager.packageWebJar = true;
    packager.deployWebJarToWisdom = true;
    packager.execute();
    final File wj = new File(packager.buildDirectory, "test-1.1-webjar.jar");
    assertThat(wj).isFile();
    JarFile jar = new JarFile(wj);
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.1/less/style.less")).isNotNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.1/missing")).isNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.1/coffee/script.coffee")).isNotNull();
    Attributes attributes = jar.getManifest().getMainAttributes();
    assertThat(attributes.getValue("Webjar-Name")).isEqualTo("test");
    assertThat(attributes.getValue("Webjar-Version")).isEqualTo("1.1");
}
 
Example #2
Source File: WebJarPackagerTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameVersionAndClassifierCustomization() throws MojoExecutionException, IOException {
    WebJarPackager packager = new WebJarPackager();
    packager.project = mock(MavenProject.class);
    packager.projectHelper = mock(MavenProjectHelper.class);
    when(packager.project.getArtifactId()).thenReturn("test");
    when(packager.project.getVersion()).thenReturn("1.0");
    when(packager.project.getBasedir()).thenReturn(fake);
    packager.buildDirectory = new File("target/junk");
    copy();
    packager.webjar = new WebJar();
    packager.webjar.setName("library");
    packager.webjar.setVersion("2.0");
    packager.webjar.setClassifier("wb");
    packager.execute();
    final File wj = new File(packager.buildDirectory, "library-2.0-wb.jar");
    assertThat(wj).isFile();
    JarFile jar = new JarFile(wj);
    assertThat(jar.getEntry(WebJarPackager.ROOT + "library/2.0/missing")).isNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "library/2.0/coffee/script.coffee")).isNotNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "library/2.0/less/style.less")).isNotNull();
    Attributes attributes = jar.getManifest().getMainAttributes();
    assertThat(attributes.getValue("Webjar-Name")).isEqualTo("library");
    assertThat(attributes.getValue("Webjar-Version")).isEqualTo("2.0");
}
 
Example #3
Source File: WebJarPackagerTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncludesCustomization() throws MojoExecutionException, IOException {
    WebJarPackager packager = new WebJarPackager();
    packager.project = mock(MavenProject.class);
    packager.projectHelper = mock(MavenProjectHelper.class);
    when(packager.project.getArtifactId()).thenReturn("test");
    when(packager.project.getVersion()).thenReturn("1.0");
    when(packager.project.getBasedir()).thenReturn(fake);
    packager.buildDirectory = new File("target/junk");
    copy();
    packager.webjar = new WebJar();
    FileSet set = new FileSet();
    set.setDirectory(new File(classes, "assets").getAbsolutePath());
    set.setIncludes(ImmutableList.of("**/coffee/*"));
    packager.webjar.setFileset(set);

    packager.execute();
    final File wj = new File(packager.buildDirectory, "test-1.0-webjar.jar");
    assertThat(wj).isFile();
    JarFile jar = new JarFile(wj);
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/missing")).isNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/coffee/script.coffee")).isNotNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/less/style.less")).isNull();
}
 
Example #4
Source File: WebJarPackagerTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testExcludesCustomization() throws MojoExecutionException, IOException {
    WebJarPackager packager = new WebJarPackager();
    packager.project = mock(MavenProject.class);
    packager.projectHelper = mock(MavenProjectHelper.class);
    when(packager.project.getArtifactId()).thenReturn("test");
    when(packager.project.getVersion()).thenReturn("1.0");
    when(packager.project.getBasedir()).thenReturn(fake);
    packager.buildDirectory = new File("target/junk");
    copy();
    packager.webjar = new WebJar();
    FileSet set = new FileSet();
    set.setDirectory(new File(classes, "assets").getAbsolutePath());
    set.setExcludes(ImmutableList.of("**/less/*"));
    packager.webjar.setFileset(set);

    packager.execute();
    final File wj = new File(packager.buildDirectory, "test-1.0-webjar.jar");
    assertThat(wj).isFile();
    JarFile jar = new JarFile(wj);
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/missing")).isNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/coffee/script.coffee")).isNotNull();
    assertThat(jar.getEntry(WebJarPackager.ROOT + "test/1.0/less/style.less")).isNull();
}
 
Example #5
Source File: AttachHelper.java    From LicenseScout with Apache License 2.0 5 votes vote down vote up
/**
 * Attaches generated report files as secondary artifacts.
 * 
 * @param mavenProject 
 * @param mavenProjectHelper 
 * @param executionParameters 
 * @param attachReportsClassifier the classifier value to for the attached report files
 * 
 */
public static void attachReports(final MavenProject mavenProject, final MavenProjectHelper mavenProjectHelper,
                                 final ExecutionParameters executionParameters,
                                 final String attachReportsClassifier) {
    for (final ExecutionOutput output : executionParameters.getOutputs()) {
        final String artifactType = output.getType().getArtifactType();
        final File artifactFile = new File(executionParameters.getOutputDirectory(),
                OutputFileHelper.getOutputFilename(output));
        executionParameters.getLsLog().info("attaching artifact: " + artifactFile.getAbsolutePath());
        mavenProjectHelper.attachArtifact(mavenProject, artifactType, attachReportsClassifier, artifactFile);
    }
}
 
Example #6
Source File: WebJarPackagerTest.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConfiguration() throws MojoExecutionException {
    WebJarPackager packager = new WebJarPackager();
    packager.project = mock(MavenProject.class);
    packager.projectHelper = mock(MavenProjectHelper.class);
    when(packager.project.getArtifactId()).thenReturn("test");
    when(packager.project.getVersion()).thenReturn("1.0");
    when(packager.project.getBasedir()).thenReturn(new File(""));
    packager.buildDirectory = new File("target");
    packager.packageWebJar = true;
    packager.deployWebJarToWisdom = true;
    packager.execute();
    // No file, so no creation
    assertThat(new File(packager.buildDirectory, "test-1.0-webjar.jar")).doesNotExist();
}
 
Example #7
Source File: AbstractScanMojo.java    From LicenseScout with Apache License 2.0 4 votes vote down vote up
/**
 * @return the mavenProjectHelper
 */
public final MavenProjectHelper getMavenProjectHelper() {
    return mavenProjectHelper;
}
 
Example #8
Source File: AntTaskUtils.java    From was-maven-plugin with Apache License 2.0 4 votes vote down vote up
public static void execute(WebSphereModel model, PlexusConfiguration target, MavenProject project,
                           MavenProjectHelper projectHelper, List<Artifact> pluginArtifact, Log logger)
    throws IOException, MojoExecutionException {
  // The fileName should probably use the plugin executionId instead of the targetName
  boolean useDefaultTargetName = false;
  String antTargetName = target.getAttribute("name");
  if (null == antTargetName) {
    antTargetName = DEFAULT_ANT_TARGET_NAME;
    useDefaultTargetName = true;
  }
  StringBuilder fileName = new StringBuilder(50);
  fileName.append("build");
  if (StringUtils.isNotBlank(model.getHost())) {
    fileName.append("-").append(model.getHost());
  }
  if (StringUtils.isNotBlank(model.getApplicationName())) {
    fileName.append("-").append(model.getApplicationName());
  }
  fileName.append("-").append(antTargetName).append("-").append(CommandUtils.getTimestampString()).append(".xml");
  File buildFile = getBuildFile(project, fileName.toString());

  if (model.isVerbose()) {
    logger.info("ant fileName: " + fileName);
  }

  if (buildFile.exists()) {
    logger.info("[SKIPPED] already executed");
    return;
  }

  StringWriter writer = new StringWriter();
  AntXmlPlexusConfigurationWriter xmlWriter = new AntXmlPlexusConfigurationWriter();
  xmlWriter.write(target, writer);

  StringBuffer antXML = writer.getBuffer();

  if (useDefaultTargetName) {
    stringReplace(antXML, "<target", "<target name=\"" + antTargetName + "\"");
  }

  final String xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
  antXML.insert(0, xmlHeader);
  final String projectOpen = "<project name=\"" + Constants.PLUGIN_ID + "\" default=\"" + antTargetName + "\">\n";
  int index = antXML.indexOf("<target");
  antXML.insert(index, projectOpen);

  final String projectClose = "\n</project>";
  antXML.append(projectClose);

  buildFile.getParentFile().mkdirs();
  FileUtils.fileWrite(buildFile.getAbsolutePath(), "UTF-8", antXML.toString());

  Project antProject = generateAntProject(model, buildFile, project, projectHelper, pluginArtifact, logger);
  antProject.executeTarget(antTargetName);
}