예제 #1
0
 /**
  * @param name name
  * @param url url
  * @return repository configuration by name and url
  */
 private Repository createRepoParameter(String name, String url) {
   Repository r = new Repository();
   r.setId(name);
   r.setName(name);
   r.setUrl(url);
   return r;
 }
예제 #2
0
 public List<String> getRepositories() {
   final List<Repository> repos = pom.getRepositories();
   if (repos == null) return null;
   final List<String> repositories = new ArrayList<String>();
   for (Repository repo : repos) repositories.add(repo.getUrl());
   return repositories;
 }
예제 #3
0
  public static ArtifactRepository buildArtifactRepository(org.apache.maven.model.Repository repo)
      throws InvalidRepositoryException {
    if (repo != null) {
      String id = repo.getId();

      if (StringUtils.isEmpty(id)) {
        throw new InvalidRepositoryException("Repository identifier missing", "");
      }

      String url = repo.getUrl();

      if (StringUtils.isEmpty(url)) {
        throw new InvalidRepositoryException("URL missing for repository " + id, id);
      }

      ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy(repo.getSnapshots());

      ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy(repo.getReleases());

      ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();

      return createArtifactRepository(id, url, layout, snapshots, releases);
    } else {
      return null;
    }
  }
  public void updatePom() throws Exception {
    File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);

    boolean pluginExists =
        MavenUtils.checkOldPluginEntry(
            mavenProject,
            "org.wso2.maven",
            "wso2-esb-template-plugin",
            MavenConstants.WSO2_ESB_TEMPLATE_VERSION);
    if (pluginExists) {
      return;
    }

    Plugin plugin =
        MavenUtils.createPluginEntry(
            mavenProject,
            "org.wso2.maven",
            "wso2-esb-template-plugin",
            MavenConstants.WSO2_ESB_TEMPLATE_VERSION,
            true);

    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("template");

    Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
    Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation");
    artifactLocationNode.setValue(".");
    Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList");
    typeListNode.setValue("${artifact.types}");
    pluginExecution.setConfiguration(configurationNode);

    plugin.addExecution(pluginExecution);
    Repository repo = new Repository();
    repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
    repo.setId("wso2-nexus");

    RepositoryPolicy releasePolicy = new RepositoryPolicy();
    releasePolicy.setEnabled(true);
    releasePolicy.setUpdatePolicy("daily");
    releasePolicy.setChecksumPolicy("ignore");

    repo.setReleases(releasePolicy);

    if (!mavenProject.getRepositories().contains(repo)) {
      mavenProject.getModel().addRepository(repo);
      mavenProject.getModel().addPluginRepository(repo);
    }

    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
  }
  @Override
  public void addRepository(Repository repository) throws InvalidRepositoryException {
    if (!repositoryIds.add(repository.getId())) {
      return;
    }

    this.repositories.add(ArtifactDescriptorUtils.toRemoteRepository(repository));
  }
예제 #6
0
  public MavenRemoteRepository(Repository repository) {
    myId = repository.getId();
    myName = repository.getName();
    myUrl = repository.getUrl();
    myLayout = repository.getLayout();

    if (repository.getReleases() != null) myReleasesPolicy = new Policy(repository.getReleases());
    if (repository.getSnapshots() != null)
      mySnapshotsPolicy = new Policy(repository.getSnapshots());
  }
예제 #7
0
 public static org.apache.maven.model.Repository fromSettingsRepository(
     org.apache.maven.settings.Repository settingsRepository) {
   org.apache.maven.model.Repository modelRepository = new org.apache.maven.model.Repository();
   modelRepository.setId(settingsRepository.getId());
   modelRepository.setLayout(settingsRepository.getLayout());
   modelRepository.setName(settingsRepository.getName());
   modelRepository.setUrl(settingsRepository.getUrl());
   modelRepository.setReleases(fromSettingsRepositoryPolicy(settingsRepository.getReleases()));
   modelRepository.setSnapshots(fromSettingsRepositoryPolicy(settingsRepository.getSnapshots()));
   return modelRepository;
 }
예제 #8
0
  public Repository toRepository() {
    Repository result = new Repository();
    result.setId(myId);
    result.setName(myName);
    result.setUrl(myUrl);
    result.setLayout(myLayout);

    if (myReleasesPolicy != null) result.setReleases(myReleasesPolicy.toRepositoryPolicy());
    if (mySnapshotsPolicy != null) result.setSnapshots(mySnapshotsPolicy.toRepositoryPolicy());

    return result;
  }
  @Test
  public void autoDiscoverWithOneCompleteLocationFromPOMRepo() throws NexusDiscoveryException {
    Settings settings = new Settings();

    String url = "http://nexus.somewhere.com/";
    String id = "some-mirror";
    String user = "******";
    String password = "******";

    testClientManager.testUrl = url;
    testClientManager.testUser = user;
    testClientManager.testPassword = password;

    Server server = new Server();
    server.setId(id);
    server.setUsername(user);
    server.setPassword(password);

    settings.addServer(server);

    Model model = new Model();
    model.setModelVersion("4.0.0");
    model.setGroupId("group.id");
    model.setArtifactId("artifact-id");
    model.setVersion("1");

    Repository repo = new Repository();
    repo.setId(id);
    repo.setUrl(url);

    model.addRepository(repo);

    MavenProject project = new MavenProject(model);

    discovery.discover(settings, project, "blah", true);
  }
  public boolean performFinish() {
    try {
      project = createNewProject();
      sourceFolder = ProjectUtils.getWorkspaceFolder(project, "src", "main", "java");
      javaProject = JavaCore.create(project);
      root = javaProject.getPackageFragmentRoot(sourceFolder);
      JavaUtils.addJavaSupportAndSourceFolder(project, sourceFolder);
      addDependancies(project);

      String className = filterModel.getFilterClass();
      String packageName = filterModel.getFilterClassPackage();

      IPackageFragment sourcePackage = root.createPackageFragment(packageName, false, null);

      ICompilationUnit cu =
          sourcePackage.createCompilationUnit(
              className + ".java", getFilterClassSource(packageName, className), false, null);
      project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

      File pomfile = project.getFile("pom.xml").getLocation().toFile();
      getModel().getMavenInfo().setPackageName("bundle");
      if (!pomfile.exists()) {
        createPOM(pomfile);
      }

      MavenProject mavenProject = MavenUtils.getMavenProject(pomfile);

      mavenProject.getModel().getProperties().put("CApp.type", "lib/registry/filter");

      Plugin plugin =
          MavenUtils.createPluginEntry(
              mavenProject, "org.apache.felix", "maven-bundle-plugin", "2.3.4", true);

      Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(plugin);
      Xpp3Dom instructionNode = MavenUtils.createXpp3Node(configurationNode, "instructions");
      Xpp3Dom symbolicNameNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-SymbolicName");
      symbolicNameNode.setValue(mavenProject.getArtifactId());
      Xpp3Dom bundleNameNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-Name");
      bundleNameNode.setValue(mavenProject.getArtifactId());
      Xpp3Dom exportPackageNode = MavenUtils.createXpp3Node(instructionNode, "Export-Package");
      exportPackageNode.setValue(packageName);
      Xpp3Dom dynamicImportNode =
          MavenUtils.createXpp3Node(instructionNode, "DynamicImport-Package");
      dynamicImportNode.setValue("*");

      Repository repo = new Repository();
      repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
      repo.setId("wso2-maven2-repository-1");

      mavenProject.getModel().addRepository(repo);
      mavenProject.getModel().addPluginRepository(repo);

      List<Dependency> dependencyList = new ArrayList<Dependency>();

      Map<String, JavaLibraryBean> dependencyInfoMap =
          JavaLibraryUtil.getDependencyInfoMap(project);
      Map<String, String> map = ProjectDependencyConstants.DEPENDENCY_MAP;
      for (JavaLibraryBean bean : dependencyInfoMap.values()) {
        if (bean.getVersion().contains("${")) {
          for (String path : map.keySet()) {
            bean.setVersion(bean.getVersion().replace(path, map.get(path)));
          }
        }
        Dependency dependency = new Dependency();
        dependency.setArtifactId(bean.getArtifactId());
        dependency.setGroupId(bean.getGroupId());
        dependency.setVersion(bean.getVersion());
        dependencyList.add(dependency);
      }
      MavenUtils.addMavenDependency(mavenProject, dependencyList);
      MavenUtils.saveMavenProject(mavenProject, pomfile);
      ProjectUtils.addNatureToProject(project, false, Constants.REGISTRY_FILTER_PROJECT_NATURE);
      MavenUtils.updateWithMavenEclipsePlugin(
          pomfile,
          new String[] {JDT_BUILD_COMMAND},
          new String[] {Constants.REGISTRY_FILTER_PROJECT_NATURE, JDT_PROJECT_NATURE});
      project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

      try {
        refreshDistProjects();
        IEditorPart javaEditor = JavaUI.openInEditor(cu);
        JavaUI.revealInEditor(javaEditor, (IJavaElement) cu);
      } catch (Exception e) {
        /* ignore */
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return true;
  }
예제 #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;
  }