@SuppressWarnings("unchecked")
  protected Configuration createConfiguration() {
    // retrievethe Build object
    Build build = getExporterMojo().getProject().getBuild();
    Log log = getExporterMojo().getLog();

    // now create an empty arraylist that is going to hold our entities
    List<String> entities = new ArrayList<String>();
    try {
      if (getExporterMojo().getComponentProperty("scan-classes", false)) {
        File outputDirectory = new File(build.getOutputDirectory());
        entities.addAll(new PersistenceClassScanner(log).scanDir(outputDirectory));
        File testOutputDirectory = new File(build.getTestOutputDirectory());
        entities.addAll(new PersistenceClassScanner(log).scanDir(testOutputDirectory));
      }

      if (getExporterMojo().getComponentProperty("scan-jars", false)) {
        for (File jarFile : getJarFiles()) {
          entities.addAll(new PersistenceClassScanner(log).scanJar(jarFile));
        }
      }
    } catch (Exception e) {
      getExporterMojo().getLog().error(e.getMessage(), e);
      return null;
    }

    // now create the configuration object
    Configuration configuration = new Configuration();
    addNamedAnnotatedClasses(configuration, entities);
    return configuration;
  }
예제 #2
0
 @Override
 public DirectoryResource getTestSourceDirectory() {
   MavenFacet mavenFacet = getFaceted().getFacet(MavenFacet.class);
   Build build = mavenFacet.getModel().getBuild();
   String srcFolderName;
   if (build != null && build.getTestSourceDirectory() != null) {
     srcFolderName = mavenFacet.resolveProperties(build.getTestSourceDirectory());
   } else {
     srcFolderName = "src" + File.separator + "test" + File.separator + "java";
   }
   DirectoryResource projectRoot = getFaceted().getRootDirectory();
   return projectRoot.getChildDirectory(srcFolderName);
 }
  @Override
  public boolean install() {
    if (!this.isInstalled()) {
      for (DirectoryResource folder : this.getSourceFolders()) {
        folder.mkdirs();
      }

      // FIXME WOW this needs to be simplified somehow...
      MavenCoreFacet maven = project.getFacet(MavenCoreFacet.class);
      Model pom = maven.getPOM();
      Build build = pom.getBuild();
      if (build == null) {
        build = new Build();
      }
      List<Plugin> plugins = build.getPlugins();
      Plugin javaSourcePlugin = null;
      for (Plugin plugin : plugins) {
        if ("org.apache.maven.plugins".equals(plugin.getGroupId())
            && "maven-compiler-plugin".equals(plugin.getArtifactId())) {
          javaSourcePlugin = plugin;
        }
      }

      if (javaSourcePlugin == null) {
        javaSourcePlugin = new Plugin();
        // FIXME this should find the most recent version using DependencyResolver
        javaSourcePlugin.setGroupId("org.apache.maven.plugins");
        javaSourcePlugin.setArtifactId("maven-compiler-plugin");
        javaSourcePlugin.setVersion("2.3.2");

        try {
          Xpp3Dom dom =
              Xpp3DomBuilder.build(
                  new ByteArrayInputStream(
                      "<configuration><source>1.6</source><target>1.6</target></configuration>"
                          .getBytes()),
                  "UTF-8");

          javaSourcePlugin.setConfiguration(dom);
        } catch (Exception e) {
          throw new ProjectModelException(e);
        }
      }

      build.addPlugin(javaSourcePlugin);
      pom.setBuild(build);
      maven.setPOM(pom);
    }
    return true;
  }
  protected void addBuild() {
    Build build = model.getBuild();
    if (build == null) {
      build = new Build();
    }

    if (bwEdition.equals("cf")) {
      boolean cfplugin = false;
      List<Plugin> plugins = build.getPlugins();
      for (Plugin plg : plugins) {
        if (plg.getArtifactId().equals("cf-maven-plugin")) {
          cfplugin = true;
        }
      }

      // Add only if doesn't exist
      if (!cfplugin) {
        addPCFWithSkipMavenPlugin(build);
      }
    } else if (bwEdition.equals("docker")) {
      boolean dockerPlugin = false;
      List<Plugin> plugins = build.getPlugins();
      for (Plugin plg : plugins) {
        if (plg.getArtifactId().equals("docker-maven-plugin")) {
          dockerPlugin = true;
        }
      }

      if (!dockerPlugin) {
        // Add docker and platform plugins if doesn't exist
        addDockerWithSkipMavenPlugin(build);

        String platform = "";
        for (BWModule module : project.getModules()) {
          if (module.getType() == BWModuleType.Application) {
            platform = module.getBwDockerModule().getPlatform();
          }
        }

        if (platform.equals("K8S")) {
          addDockerK8SMavenPlugin(build, true);
        } else if (platform.equals("Mesos")) {

        } else if (platform.equals("Swarm")) {

        }
      }
    }
    model.setBuild(build);
  }
예제 #5
0
 @Override
 public DirectoryResource getTestResourceFolder() {
   MavenCoreFacet mavenFacet = project.getFacet(MavenCoreFacet.class);
   Build build = mavenFacet.getPOM().getBuild();
   final String resFolderName;
   if (build != null
       && !build.getTestResources().isEmpty()
       && build.getTestResources().get(0).getDirectory() != null) {
     resFolderName = build.getTestResources().get(0).getDirectory();
   } else {
     resFolderName = "src" + File.separator + "test" + File.separator + "resources";
   }
   DirectoryResource projectRoot = project.getProjectRoot();
   return projectRoot.getChildDirectory(resFolderName);
 }
 static InputLocation findLocationForManagedArtifact(
     final ManagedArtifactRegion region, MavenProject mavprj) {
   Model mdl = mavprj.getModel();
   InputLocation openLocation = null;
   if (region.isDependency) {
     DependencyManagement dm = mdl.getDependencyManagement();
     if (dm != null) {
       List<Dependency> list = dm.getDependencies();
       String id = region.groupId + ":" + region.artifactId + ":"; // $NON-NLS-1$ //$NON-NLS-2$
       if (list != null) {
         for (Dependency dep : list) {
           if (dep.getManagementKey().startsWith(id)) {
             InputLocation location = dep.getLocation(ARTIFACT_ID); // $NON-NLS-1$
             // when would this be null?
             if (location != null) {
               openLocation = location;
               break;
             }
           }
         }
       }
     }
   }
   if (region.isPlugin) {
     Build build = mdl.getBuild();
     if (build != null) {
       PluginManagement pm = build.getPluginManagement();
       if (pm != null) {
         List<Plugin> list = pm.getPlugins();
         String id = Plugin.constructKey(region.groupId, region.artifactId);
         if (list != null) {
           for (Plugin plg : list) {
             if (id.equals(plg.getKey())) {
               InputLocation location = plg.getLocation(ARTIFACT_ID); // $NON-NLS-1$
               // when would this be null?
               if (location != null) {
                 openLocation = location;
                 break;
               }
             }
           }
         }
       }
     }
   }
   return openLocation;
 }
예제 #7
0
  public void execute() throws MojoExecutionException, MojoFailureException {

    getLog().info("Building JavaFX JAR for application");

    Build build = project.getBuild();

    CreateJarParams createJarParams = new CreateJarParams();
    createJarParams.setOutdir(jfxAppOutputDir);
    createJarParams.setOutfile(jfxMainAppJarName);
    createJarParams.setApplicationClass(mainClass);
    createJarParams.setCss2bin(css2bin);
    createJarParams.addResource(new File(build.getOutputDirectory()), "");
    createJarParams.setPreloader(preLoader);
    StringBuilder classpath = new StringBuilder();
    File libDir = new File(jfxAppOutputDir, "lib");
    if (!libDir.exists() && !libDir.mkdirs()) {
      throw new MojoExecutionException("Unable to create app lib dir: " + libDir);
    }

    try {
      for (Object object : project.getRuntimeClasspathElements()) {
        String path = (String) object;
        File file = new File(path);
        if (file.isFile()) {
          getLog().debug("Including classpath element: " + path);
          File dest = new File(libDir, file.getName());
          if (!dest.exists()) {
            Files.copy(file.toPath(), dest.toPath());
          }
          classpath.append("lib/").append(file.getName()).append(" ");
        }
      }
    } catch (DependencyResolutionRequiredException e) {
      throw new MojoExecutionException(
          "Error resolving application classpath to use for application", e);
    } catch (IOException e) {
      throw new MojoExecutionException("Error copying dependency for application", e);
    }
    createJarParams.setClasspath(classpath.toString());

    try {
      getPackagerLib().packageAsJar(createJarParams);
    } catch (PackagerException e) {
      throw new MojoExecutionException("Unable to build JFX JAR for application", e);
    }
  }
  @Test
  public void testPackagingOfMavenAppWithCustomGAV() throws IOException, MojoExecutionException {
    if (!Helper.detectPlay2()) {
      System.err.println("PLAY2_HOME missing, skipping tests");
      return;
    }

    File baseDir = new File("target/tests/testPackagingOfMavenAppWithCustomGAV");
    Helper.copyMavenApp(baseDir);

    Play2PackageMojo mojo = new Play2PackageMojo();

    mojo.project = mock(MavenProject.class);
    mojo.projectHelper = mock(MavenProjectHelper.class);
    mojo.attachDist = true;
    mojo.buildDist = true;
    mojo.deleteDist = false;
    mojo.buildDirectory = new File(baseDir, "target");
    mojo.setLog(new SystemStreamLog());
    Build build = mock(Build.class);
    Artifact artifact = mock(Artifact.class);

    when(mojo.project.getBasedir()).thenReturn(baseDir);
    when(mojo.project.getBuild()).thenReturn(build);
    when(mojo.project.getArtifact()).thenReturn(artifact);
    when(build.getFinalName()).thenReturn("my-artifact-id-1.0.0");
    when(mojo.project.getArtifactId()).thenReturn("my-artifact-id");
    when(mojo.project.getGroupId()).thenReturn("my-group-id");
    when(mojo.project.getVersion()).thenReturn("1.0.0");

    mojo.execute();

    // Verify attached file
    File target = new File(baseDir, "target");
    File dist = new File(target, "my-artifact-id-1.0.0.zip");
    File pack = new File(target, "my-artifact-id-1.0.0.jar");
    assertThat(dist).exists();
    assertThat(pack).exists();
    verify(artifact).setFile(pack);
    verify(mojo.projectHelper).attachArtifact(mojo.project, "zip", null, dist);
  }
예제 #9
0
  public Map<String, Plugin> getManagedPluginMap(final ModelBase base) {
    if (base instanceof Model) {
      final Build build = ((Model) base).getBuild();
      if (build == null) {
        return Collections.<String, Plugin>emptyMap();
      }

      final PluginManagement pm = build.getPluginManagement();
      if (pm == null) {
        return Collections.<String, Plugin>emptyMap();
      }

      final Map<String, Plugin> result = pm.getPluginsAsMap();
      if (result == null) {
        return Collections.<String, Plugin>emptyMap();
      }

      return result;
    }

    return Collections.<String, Plugin>emptyMap();
  }
예제 #10
0
  public void testProjectInheritance() throws Exception {
    File localRepo = getLocalRepositoryPath();

    System.out.println("Local repository is at: " + localRepo.getAbsolutePath());

    File pom0 = new File(localRepo, "p0/pom.xml");
    File pom1 = new File(pom0.getParentFile(), "p1/pom.xml");
    File pom2 = new File(pom1.getParentFile(), "p2/pom.xml");
    File pom3 = new File(pom2.getParentFile(), "p3/pom.xml");
    File pom4 = new File(pom3.getParentFile(), "p4/pom.xml");
    File pom5 = new File(pom4.getParentFile(), "p5/pom.xml");

    System.out.println("Location of project-4's POM: " + pom4.getPath());

    // load everything...
    MavenProject project0 = getProject(pom0);
    MavenProject project1 = getProject(pom1);
    MavenProject project2 = getProject(pom2);
    MavenProject project3 = getProject(pom3);
    MavenProject project4 = getProject(pom4);
    MavenProject project5 = getProject(pom5);

    assertEquals("p4", project4.getName());

    // ----------------------------------------------------------------------
    // Value inherited from p3
    // ----------------------------------------------------------------------

    assertEquals("2000", project4.getInceptionYear());

    // ----------------------------------------------------------------------
    // Value taken from p2
    // ----------------------------------------------------------------------

    assertEquals("mailing-list", project4.getMailingLists().get(0).getName());

    // ----------------------------------------------------------------------
    // Value taken from p1
    // ----------------------------------------------------------------------

    assertEquals("scm-url/p2/p3/p4", project4.getScm().getUrl());

    // ----------------------------------------------------------------------
    // Value taken from p4
    // ----------------------------------------------------------------------

    assertEquals("Codehaus", project4.getOrganization().getName());

    // ----------------------------------------------------------------------
    // Value taken from super model
    // ----------------------------------------------------------------------

    assertEquals("4.0.0", project4.getModelVersion());

    Build build = project4.getBuild();
    List plugins = build.getPlugins();

    Map validPluginCounts = new HashMap();

    String testPluginArtifactId = "maven-compiler-plugin";

    // this is the plugin we're looking for.
    validPluginCounts.put(testPluginArtifactId, 0);

    // these are injected if -DperformRelease=true
    validPluginCounts.put("maven-deploy-plugin", 0);
    validPluginCounts.put("maven-javadoc-plugin", 0);
    validPluginCounts.put("maven-source-plugin", 0);

    Plugin testPlugin = null;

    for (Iterator it = plugins.iterator(); it.hasNext(); ) {
      Plugin plugin = (Plugin) it.next();

      String pluginArtifactId = plugin.getArtifactId();

      if (!validPluginCounts.containsKey(pluginArtifactId)) {
        fail("Illegal plugin found: " + pluginArtifactId);
      } else {
        if (pluginArtifactId.equals(testPluginArtifactId)) {
          testPlugin = plugin;
        }

        Integer count = (Integer) validPluginCounts.get(pluginArtifactId);

        if (count.intValue() > 0) {
          fail("Multiple copies of plugin: " + pluginArtifactId + " found in POM.");
        } else {
          count = count.intValue() + 1;

          validPluginCounts.put(pluginArtifactId, count);
        }
      }
    }

    List executions = testPlugin.getExecutions();

    assertEquals(1, executions.size());
  }
예제 #11
0
  public Model toMavenModel() {
    Model model = new Model();
    model.setBuild(new Build());
    model.setDescription(description);
    model.setUrl(url);
    model.setName(projectId.getArtifact());
    model.setGroupId(projectId.getGroup());
    model.setVersion(projectId.getVersion());
    model.setArtifactId(projectId.getArtifact());
    model.setModelVersion("4.0.0");

    // parent
    if (parent != null) {
      model.setParent(parent);
    }

    model.setPackaging(packaging);

    if (properties != null) {
      Properties modelProperties = new Properties();
      for (Property p : properties) {
        modelProperties.setProperty(p.getKey(), p.getValue());
      }
      model.setProperties(modelProperties);
    }

    // Add jar repository urls.
    if (null != repositories) {
      for (String repoUrl : repositories.getRepositories()) {
        Repository repository = new Repository();
        repository.setId(Integer.toString(repoUrl.hashCode()));
        repository.setUrl(repoUrl);
        model.addRepository(repository);
      }
    }

    // Add dependency management
    if (overrides != null) {
      DependencyManagement depMan = new DependencyManagement();
      for (Id dep : overrides) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        depMan.addDependency(dependency);
      }
      model.setDependencyManagement(depMan);
    }

    // Add project dependencies.
    if (deps != null) {
      for (Id dep : deps) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        model.addDependency(dependency);
      }
    }

    if (modules != null) {
      model.setModules(modules);
    }

    if (pluginOverrides != null) {
      PluginManagement management = new PluginManagement();
      management.setPlugins(pluginOverrides);
      model.getBuild().setPluginManagement(management);
    }

    if (plugins != null) {
      model.getBuild().setPlugins(plugins);
    }

    // Optional source dirs customization.
    if (dirs != null) {
      Build build = new Build();
      String srcDir = dirs.get("src");
      String testDir = dirs.get("test");

      if (null != srcDir) build.setSourceDirectory(srcDir);

      if (null != testDir) build.setTestSourceDirectory(testDir);

      model.setBuild(build);
    }

    if (null != scm) {
      Scm scm = new Scm();
      scm.setConnection(this.scm.getConnection());
      scm.setDeveloperConnection(this.scm.getDeveloperConnection());
      scm.setUrl(this.scm.getUrl());

      model.setScm(scm);
    }

    return model;
  }
  /**
   * If enabled, grab the execution root pom (which will be the topmost POM in terms of directory
   * structure). Check for the presence of the project-sources-maven-plugin in the base build
   * (/project/build/plugins/). Inject a new plugin execution for creating project sources if this
   * plugin has not already been declared in the base build section.
   */
  @Override
  public Set<Project> applyChanges(final List<Project> projects, final ManipulationSession session)
      throws ManipulationException {
    final ProjectSourcesInjectingState state = session.getState(ProjectSourcesInjectingState.class);

    // This manipulator will only run if its enabled *and* at least one other manipulator is
    // enabled.
    if (state.isEnabled() && session.anyStateEnabled(State.activeByDefault)) {
      for (final Project project : projects) {
        if (project.isExecutionRoot()) {
          logger.info("Examining {} to apply sources/metadata plugins.", project);

          final Model model = project.getModel();
          Build build = model.getBuild();
          if (build == null) {
            build = new Build();
            model.setBuild(build);
          }

          boolean changed = false;
          final Map<String, Plugin> pluginMap = build.getPluginsAsMap();
          if (state.isProjectSourcesPluginEnabled()
              && !pluginMap.containsKey(PROJECT_SOURCES_COORD)) {
            final PluginExecution execution = new PluginExecution();
            execution.setId(PROJECT_SOURCES_EXEC_ID);
            execution.setPhase(INITIALIZE_PHASE);
            execution.setGoals(Collections.singletonList(PROJECT_SOURCES_GOAL));

            final Plugin plugin = new Plugin();
            plugin.setGroupId(PROJECT_SOURCES_GID);
            plugin.setArtifactId(PROJECT_SOURCES_AID);
            plugin.setVersion(state.getProjectSourcesPluginVersion());
            plugin.addExecution(execution);

            build.addPlugin(plugin);

            changed = true;
          }

          if (state.isBuildMetadataPluginEnabled() && !pluginMap.containsKey(BMMP_COORD)) {
            final PluginExecution execution = new PluginExecution();
            execution.setId(BMMP_EXEC_ID);
            execution.setPhase(VALIDATE_PHASE);
            execution.setGoals(Collections.singletonList(BMMP_GOAL));

            final Xpp3Dom xml = new Xpp3Dom("configuration");

            final Map<String, Object> config = new HashMap<>();
            config.put("createPropertiesReport", true);
            config.put("hideCommandLineInfo", false);
            config.put("hideJavaOptsInfo", false);
            config.put("activateOutputFileMapping", true);
            config.put("addJavaRuntimeInfo", true);

            // Default name is build.properties but we currently prefer build.metadata.
            config.put("propertiesOutputFile", "build.metadata");
            // Deactivate features we don't want.
            config.put("createXmlReport", false);
            config.put("addLocallyModifiedTagToFullVersion", false);
            config.put("addToGeneratedSources", false);
            config.put("validateCheckout", false);
            config.put("forceNewProperties", true);
            config.put("addBuildDateToFullVersion", false);
            config.put("addHostInfo", false);
            config.put("addBuildDateInfo", false);
            config.put("addOsInfo", false);
            config.put("addMavenExecutionInfo", false);
            config.put("addToFilters", false);

            final Xpp3Dom additionalLocations = new Xpp3Dom("addToLocations");
            final Xpp3Dom additionalLocation = new Xpp3Dom("addToLocation");

            xml.addChild(additionalLocations);
            additionalLocations.addChild(additionalLocation);
            additionalLocation.setValue("${session.executionRootDirectory}");

            for (final Map.Entry<String, Object> entry : config.entrySet()) {
              final Xpp3Dom child = new Xpp3Dom(entry.getKey());
              if (entry.getValue() != null) {
                child.setValue(entry.getValue().toString());
              }

              xml.addChild(child);
            }

            execution.setConfiguration(xml);

            final Plugin plugin = new Plugin();
            plugin.setGroupId(BMMP_GID);
            plugin.setArtifactId(BMMP_AID);
            plugin.setVersion(state.getBuildMetadataPluginVersion());
            plugin.addExecution(execution);

            build.addPlugin(plugin);

            changed = true;
          }

          if (changed) {
            return Collections.singleton(project);
          }
        }
      }
    }

    return Collections.emptySet();
  }