/**
   * Creates a Verifier against passed in {@link MavenDeployment}.
   *
   * @param mavenDeployment
   * @return
   * @throws VerificationException
   * @throws IOException
   */
  public Verifier createMavenVerifier(final MavenDeployment mavenDeployment)
      throws VerificationException, IOException {
    System.setProperty("maven.home", mavenDeployment.getMavenHomeFile().getAbsolutePath());
    Verifier verifier =
        new Verifier(mavenDeployment.getMavenProjectFile().getAbsolutePath()) {
          @Override
          public void executeGoals(List<String> goals, Map envVars) throws VerificationException {
            try {
              super.executeGoals(goals, envVars);
            } catch (VerificationException e) {
              // HACK: Strip out the entire log which is included in the message by default! :-(
              File logFile = new File(getBasedir(), getLogFileName());
              throw new VerificationException(
                  "Goals execution failed: "
                      + goals
                      + "; see log for more details: "
                      + logFile.getAbsolutePath(),
                  e.getCause());
            }
          }
        };
    verifier.setLogFileName(mavenDeployment.getLogFileName());
    verifier.setLocalRepo(mavenDeployment.getLocalRepositoryFile().getAbsolutePath());
    verifier.resetStreams();

    List<String> options = new ArrayList<String>();
    options.add("-X");
    options.add("-Dmaven.repo.local=" + mavenDeployment.getLocalRepositoryFile().getAbsolutePath());
    options.add("-s " + mavenDeployment.getSettingsXmlFile().getAbsolutePath());
    verifier.setCliOptions(options);
    return verifier;
  }
  @Test(groups = SECURITY)
  public void deployRepeatly() throws Exception {
    File mavenProject1 = getTestFile("maven-project-1");

    File settings1 = getTestFile("settings1.xml");

    Verifier verifier1 = null;

    try {
      verifier1 = createVerifier(mavenProject1, settings1);

      verifier1.executeGoal("deploy");

      verifier1.verifyErrorFreeLog();
    } catch (VerificationException e) {
      failTest(verifier1);
    }

    try {
      verifier1.executeGoal("deploy");

      verifier1.verifyErrorFreeLog();

      Assert.fail("Should return 401 error");
    } catch (VerificationException e) {
      // 401 error
    }
  }
  /** Test that the CLI parameter -l can be used to direct logging to a file. */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3183");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.addCliOption("-l");
    verifier.addCliOption("maven.log");
    verifier.setLogFileName("stdout.txt");
    new File(testDir, "stdout.txt").delete();
    new File(testDir, "maven.log").delete();
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List<String> stdout = verifier.loadLines("stdout.txt", "UTF-8");

    for (Iterator<String> it = stdout.iterator(); it.hasNext(); ) {
      String line = it.next();
      if (line.startsWith("+") || line.startsWith("EMMA")) {
        it.remove();
      }
    }

    assertEquals(Collections.EMPTY_LIST, stdout);

    List<String> log = verifier.loadLines("maven.log", "UTF-8");

    assertFalse(log.isEmpty());
  }
  public void run() {
    status = "started";
    File mavenProject = getTestFile("pom.xml").getParentFile();

    System.setProperty("maven.home", TestProperties.getString("maven.instance"));
    Verifier verifier;
    try {
      verifier = new Verifier(mavenProject.getAbsolutePath(), false);
      status = "verifierCreated";
    } catch (VerificationException e) {
      status = "failCreation" + e.getMessage();
      return;
    }

    File mavenRepository = new File(TestProperties.getString("maven.local.repo"));
    verifier.setLocalRepo(mavenRepository.getAbsolutePath());

    verifier.resetStreams();

    List<String> options = new ArrayList<String>();
    options.add("-X");
    options.add("-Dmaven.repo.local=" + mavenRepository.getAbsolutePath());
    options.add("-s " + getOverridableFile("settings.xml"));
    verifier.setCliOptions(options);

    status = "pre-execute";
    try {
      verifier.executeGoal("dependency:resolve");
      status = "executed";
    } catch (VerificationException e) {
      status = "failExecute" + e.getMessage();
    }
  }
  @Test
  public void testPomlessBuildExtension() throws Exception {
    Verifier verifier = getVerifier("testsetversionpomless", false);
    String newVersion = "2.0.0";
    verifier.addCliOption("-DnewVersion=" + newVersion);
    verifier.executeGoal(
        "org.eclipse.tycho:tycho-versions-plugin:" + getTychoVersion() + ":set-version");
    verifier.verifyErrorFreeLog();
    File baseDir = new File(verifier.getBasedir());

    PomFile rootPom = PomFile.read(new File(baseDir, "pom.xml"), false);
    Assert.assertEquals(newVersion, rootPom.getVersion());

    DefaultBundleReader reader = new DefaultBundleReader();
    OsgiManifest bundleManifest =
        reader.loadManifest(new File(baseDir, "bundle1/META-INF/MANIFEST.MF"));
    Assert.assertEquals(newVersion, bundleManifest.getBundleVersion());

    OsgiManifest testBundleManifest =
        reader.loadManifest(new File(baseDir, "bundle1.tests/META-INF/MANIFEST.MF"));
    Assert.assertEquals(newVersion, testBundleManifest.getBundleVersion());

    Feature feature = Feature.read(new File(baseDir, "feature/feature.xml"));
    Assert.assertEquals(newVersion, feature.getVersion());
  }
 @Test
 public void requireBundle() throws Exception {
   Verifier verifier = getVerifier("/compiler.optionalDependencies/require-bundle", false);
   verifier.getCliOptions().add("-De342-repo=" + P2Repositories.ECLIPSE_342.toString());
   verifier.executeGoals(Arrays.asList("clean", "verify"));
   verifier.verifyErrorFreeLog();
 }
 @Test
 public void test() throws Exception {
   Verifier verifier = getVerifier("/363331_extraTargetPlatformRequirements", false);
   verifier.getCliOptions().add("-De342-repo=" + P2Repositories.ECLIPSE_342.toString());
   verifier.getCliOptions().add("-De352-repo=" + P2Repositories.ECLIPSE_352.toString());
   verifier.executeGoals(Arrays.asList("clean", "install"));
   verifier.verifyErrorFreeLog();
 }
  private void download() throws Exception {

    Verifier v =
        AbstractMavenNexusIT.createMavenVerifier(
            getTestFile("project"), getOverridableFile("settings.xml"), getTestId());

    v.executeGoal("install");
  }
 private void configureProcessor(ProcessorTestCase child, Verifier verifier) {
   if (child.processor.getCompilerId() != null) {
     verifier.addCliOption("-Pgenerate-via-compiler-plugin");
     verifier.addCliOption("-Dcompiler-id=" + child.processor.getCompilerId());
   } else {
     verifier.addCliOption("-Pgenerate-via-processor-plugin");
   }
 }
 private Verifier getVerifier(String project, File baselineRepo) throws Exception {
   Verifier verifier = getVerifier("/packaging.reproducibleArtifacts/" + project, false);
   verifier
       .getCliOptions()
       .add("-De342-repo=" + ResourceUtil.P2Repositories.ECLIPSE_342.toString());
   verifier.getCliOptions().add("-Dbaseline-repo=" + baselineRepo.toURI().toString());
   return verifier;
 }
  @Test
  public void testBaselineDisable() throws Exception {
    Verifier verifier = getVerifier("contentchanged", baselineRepo);

    verifier.getCliOptions().add("-Dtycho.baseline=disable");

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyErrorFreeLog();
  }
 @Test
 public void dependencyDownload() throws Exception {
   try {
     verifier.executeGoal("dependency:resolve");
     verifier.verifyErrorFreeLog();
   } catch (VerificationException e) {
     failTest(verifier);
   }
 }
  @Test
  public void testBaselineRepositoryDoesNotExist() throws Exception {
    // likely initial state is when baseline repository url points at empty or garbage location
    File notARepository = new File("baseline/src").getCanonicalFile();
    Verifier verifier = getVerifier("baseline/src", notARepository);

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyErrorFreeLog();
  }
  @Before
  public void setUp() throws VerificationException, IOException {
    Verifier verifier = new Verifier(getRoot().getAbsolutePath());

    // Deleting a former created artefact from the archetype to be tested
    verifier.deleteArtifact(getGroupId(), getArtifactId(), getArtifactVersion(), null);

    // Delete the created maven project
    verifier.deleteDirectory(getArtifactId());
  }
  @Test
  public void buildExecutable() throws VerificationException {
    Verifier verifier = new Verifier(getRoot().getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.setMavenDebug(true);

    verifier.executeGoal("package");

    verifier.verifyErrorFreeLog();
  }
  @Test
  public void testBaselineWarn() throws Exception {
    Verifier verifier = getVerifier("contentchanged", baselineRepo);

    verifier.getCliOptions().add("-Dtycho.baseline=warn");

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyTextInLog(
        "baseline and build artifacts have same version but different contents");
  }
  @Test
  public void testBaselineFailCommon_newAttachedArtifact() throws Exception {
    Verifier verifier = getVerifier("newattachedartifact", baselineRepo);

    verifier.getCliOptions().add("-Dtycho.baseline=failCommon");

    verifier.executeGoals(Arrays.asList("clean", "package"));

    verifier.verifyTextInLog(
        "baseline and build artifacts have same version but different contents");
  }
Exemple #18
0
  @Test
  public void should_app_generated_executes_maven_well() throws IOException, VerificationException {
    RestxShell shell = prepareRestxShell();

    AppShellCommand.NewAppCommandRunner appCommandRunner =
        new AppShellCommand().new NewAppCommandRunner();
    Path appPath = appCommandRunner.generateApp(descriptor, shell);

    Verifier mavenVerifier = new Verifier(appPath.toString());
    mavenVerifier.executeGoal("package");
    mavenVerifier.verifyErrorFreeLog();
  }
  // Depends on nexus-508
  @Test
  public void dependencyDownloadProtectedServer() throws Exception {
    // Disable anonymous
    disableUser("anonymous");

    File mavenProject = getTestFile("maven-project");
    File settings = getTestFile("repositoriesWithAuthentication.xml");

    Verifier verifier = createVerifier(mavenProject, settings);
    verifier.executeGoal("dependency:resolve");
    verifier.verifyErrorFreeLog();
  }
  @Test
  public void testContentChangedStrict() throws Exception {
    Verifier verifier = getVerifier("contentchanged", baselineRepo);

    try {
      verifier.executeGoals(Arrays.asList("clean", "package"));
    } catch (VerificationException expected) {
      //
    }
    verifier.verifyTextInLog(
        "baseline and build artifacts have same version but different contents");
  }
  @Test
  public void testRepository() throws Exception {
    String url = server.addServer("foo", new File("repositories/e342"));

    Verifier verifier =
        getVerifier(
            "/TYCHO319passwordProtectedP2Repository",
            false,
            new File("projects/TYCHO319passwordProtectedP2Repository/settings.xml"));
    verifier.getCliOptions().add("-P=repository");
    verifier.executeGoals(Arrays.asList("package", "-Dp2.repo=" + url));
    verifier.verifyErrorFreeLog();
  }
  @Test
  public void testBaselineWarn_changedAttachedArtifact() throws Exception {
    Verifier verifier = getVerifier("changedattachedartifact", baselineRepo);

    verifier.getCliOptions().add("-Dtycho.baseline=warn");

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyTextInLog(
        "baseline and build artifacts have same version but different contents");

    File repository = new File(verifier.getBasedir(), "repository/target/repository");
    assertBaselineContents(repository, "plugins/baseline.bundle01.source_1.0.0.1.jar");
  }
  @Test
  public void dependencyDownloadPrivateServer() throws Exception {
    // Disable anonymous
    disableUser("anonymous");

    try {
      verifier.executeGoal("dependency:resolve");
      verifier.verifyErrorFreeLog();
      failTest(verifier);
    } catch (VerificationException e) {
      // Expected exception
    }
  }
  @Test
  public void testRebuildOfTheSameCodebase() throws Exception {
    Verifier verifier = getVerifier("baseline/src", baselineRepo);

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyErrorFreeLog();

    File repository = new File(verifier.getBasedir(), "repository/target/repository");

    assertBaselineContents(repository, "features/baseline.feature01_1.0.0.1.jar");
    assertBaselineContents(repository, "plugins/baseline.bundle01_1.0.0.1.jar");
    assertBaselineContents(repository, "plugins/baseline.bundle01.source_1.0.0.1.jar");
  }
  /**
   * @param baseDir
   * @param model
   * @throws VerificationException
   */
  private void installArchetype(File baseDir, Model model) throws VerificationException {
    log.info("Installing Archetype *****: " + model);
    Verifier installer = new Verifier(baseDir.getAbsolutePath());
    if (onlyMavenCentral) {
      installer.addCliOption("-s " + testOutputDirectory + File.separator + "settings-clear.xml");
    }
    installer.setLogFileName("install.log");
    installer.setAutoclean(cleanArchetypes);
    installer.executeGoal("install");

    // Remove install.log from inside archetype
    new File(baseDir, "install.log").delete();
  }
  private void doExecute(ProcessorTestCase child, Description description) throws Exception {
    File destination = extractTest(child, description);
    PrintStream originalOut = System.out;

    final Verifier verifier;
    if (Boolean.getBoolean(SYS_PROP_DEBUG)) {
      if (child.processor.getToolchain() == null) {
        // when not using toolchains for a test, then the compiler is executed within the Maven JVM.
        // So make
        // sure we fork a new JVM for that, and let that new JVM use the command 'mvnDebug' instead
        // of 'mvn'
        verifier = new Verifier(destination.getCanonicalPath(), null, true, true);
        verifier.setDebugJvm(true);
      } else {
        verifier = new Verifier(destination.getCanonicalPath());
        verifier.addCliOption("-Pdebug-forked-javac");
      }
    } else {
      verifier = new Verifier(destination.getCanonicalPath());
    }

    List<String> goals = new ArrayList<String>(3);

    goals.add("clean");

    try {
      configureToolchains(child, verifier, goals, originalOut);
      configureProcessor(child, verifier);

      verifier.addCliOption(
          "-Dcompiler-source-target-version=" + child.processor.getSourceTargetVersion());

      if ("1.8".equals(child.processor.getSourceTargetVersion())
          || "1.9".equals(child.processor.getSourceTargetVersion())) {
        verifier.addCliOption("-Dmapstruct-artifact-id=mapstruct-jdk8");
      } else {
        verifier.addCliOption("-Dmapstruct-artifact-id=mapstruct");
      }

      if (Boolean.getBoolean(SYS_PROP_DEBUG)) {
        originalOut.print("Processor Integration Test: ");
        originalOut.println("Listening for transport dt_socket at address: 8000 (in some seconds)");
      }

      goals.add("test");

      addAdditionalCliArguments(child, verifier);

      originalOut.println("executing " + child.processor.name().toLowerCase());

      verifier.executeGoals(goals);
      verifier.verifyErrorFreeLog();
    } finally {
      verifier.resetStreams();
    }
  }
  @Test
  public void testBaselineFail_changedAttachedArtifact() throws Exception {
    Verifier verifier = getVerifier("changedattachedartifact", baselineRepo);

    verifier.getCliOptions().add("-Dtycho.baseline=fail");

    try {
      verifier.executeGoals(Arrays.asList("clean", "package"));
    } catch (VerificationException expected) {
      //
    }
    verifier.verifyTextInLog(
        "baseline and build artifacts have same version but different contents");
  }
  private void configureToolchains(
      ProcessorTestCase child, Verifier verifier, List<String> goals, PrintStream originalOut) {
    if (child.processor.getToolchain() != null) {
      verifier.addCliOption("--toolchains");
      verifier.addCliOption(TOOLCHAINS_FILE.getPath().replace('\\', '/'));

      Toolchain toolchain = child.processor.getToolchain();

      verifier.addCliOption("-Dtoolchain-jdk-vendor=" + toolchain.getVendor());
      verifier.addCliOption("-Dtoolchain-jdk-version=" + toolchain.getVersionRangeString());

      goals.add("toolchains:toolchain");
    }
  }
  /**
   * Test that POM interpolation uses the property values from the dominant profile source (POM vs.
   * profiles.xml vs. settings.xml). This boils down to the proper order of profile injection and
   * interpolation, i.e. interpolate after profiles from all sources are injected.
   */
  public void testitMNG4107() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4107");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.addCliOption("--settings");
    verifier.addCliOption("settings.xml");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    Properties props = verifier.loadProperties("target/pom.properties");

    assertEquals("applied", props.getProperty("project.properties.pomProfile"));
    assertEquals("applied", props.getProperty("project.properties.settingsProfile"));
    assertEquals("settings", props.getProperty("project.properties.pomVsSettings"));
    assertEquals("settings", props.getProperty("project.properties.pomVsSettingsInterpolated"));

    if (matchesVersionRange("(,3.0-alpha-1)")) {
      // MNG-4060, profiles.xml support dropped
      assertEquals("applied", props.getProperty("project.properties.profilesProfile"));
      assertEquals("profiles", props.getProperty("project.properties.pomVsProfiles"));
      assertEquals("profiles", props.getProperty("project.properties.pomVsProfilesInterpolated"));
      assertEquals("settings", props.getProperty("project.properties.profilesVsSettings"));
      assertEquals(
          "settings", props.getProperty("project.properties.profilesVsSettingsInterpolated"));
    }
  }
  public void testitMNG3485() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3485");

    Verifier verifier;

    verifier = newVerifier(testDir.getAbsolutePath(), "remote");

    verifier.executeGoal("deploy");

    verifier.assertFilePresent("target/wagon.properties");
    verifier.verifyErrorFreeLog();

    verifier.resetStreams();
  }