private String getMvnLocationFromArtifact(Artifact artifact){ if (artifact == null) return null; StringBuilder bundleLocation = new StringBuilder(); bundleLocation.append("mvn:"); bundleLocation.append(artifact.getGroupId()).append('/').append(artifact.getArtifactId()).append('/').append(artifact.getVersion()); return bundleLocation.toString(); }
public synchronized LifecycleResults reloadConfiguration(Artifact id, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { return reloadConfiguration(id, id.getVersion(), monitor); }
public File getLocation(Artifact artifact) { if(!artifact.isResolved()) { throw new IllegalArgumentException("Artifact "+artifact+" is not fully resolved"); } File path = new File(rootFile, artifact.getGroupId().replace('.', File.separatorChar)); path = new File(path, artifact.getArtifactId()); path = new File(path, artifact.getVersion().toString()); path = new File(path, artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getType()); return path; }
private URL getURL(Artifact configId) throws MalformedURLException { String qualifiedVersion = configId.getVersion().toString(); if (configId.getVersion() instanceof SnapshotVersion) { SnapshotVersion ssVersion = (SnapshotVersion) configId.getVersion(); String timestamp = ssVersion.getTimestamp(); int buildNumber = ssVersion.getBuildNumber(); if (timestamp != null && buildNumber != 0) { qualifiedVersion = qualifiedVersion.replaceAll("SNAPSHOT", timestamp + "-" + buildNumber); } } return base.resolve(configId.getGroupId().replace('.', '/') + "/" + configId.getArtifactId() + "/" + configId.getVersion() + "/" + configId.getArtifactId() + "-" + qualifiedVersion + "." + configId.getType()).toURL(); }
public File getLocation(Artifact artifact) { File path = new File(rootFile, artifact.getGroupId()); path = new File(path, artifact.getType() + "s"); String ext = artifact.getType(); if(ext.equals("ejb")) { ext = "jar"; } path = new File(path, artifact.getArtifactId() + "-" + artifact.getVersion() + "." + ext); return path; }
private boolean hasHardDependency(Artifact configurationId, ConfigurationData configurationData) { for (Iterator iterator = configurationData.getEnvironment().getDependencies().iterator(); iterator.hasNext();) { Dependency dependency = (Dependency) iterator.next(); Artifact artifact = dependency.getArtifact(); if (artifact.getVersion() != null && artifact.matches(configurationId)) { return true; } } for (Iterator iterator = configurationData.getChildConfigurations().values().iterator(); iterator.hasNext();) { ConfigurationData childConfigurationData = (ConfigurationData) iterator.next(); if (hasHardDependency(configurationId, childConfigurationData)) { return true; } } return false; }
public Artifact generateArtifact(Artifact source, String defaultType) { if(source.isResolved()) { Artifact deAliased = (Artifact) explicitResolution.get(source); if (deAliased != null) { return deAliased; } return source; } String groupId = source.getGroupId() == null ? Artifact.DEFAULT_GROUP_ID : source.getGroupId(); String artifactId = source.getArtifactId(); String type = source.getType() == null ? defaultType : source.getType(); Version version = source.getVersion() == null ? new Version(Long.toString(System.currentTimeMillis())) : source.getVersion(); return new Artifact(groupId, artifactId, version, type); }
public void installLibrary(File libFile, Artifact artifact) throws IOException { if (artifact == null || !artifact.isResolved()) throw new IllegalArgumentException("Artifact is not valid when install library"); if (identifyOSGiBundle(libFile) != null) { writeableRepo.copyToRepository(libFile, artifact, new RepoFileWriteMonitor()); } else { // convert to osgi bundle jars using wrap url handler URL wrap = new URL("wrap", null, libFile.toURI().toURL().toExternalForm() + "$Bundle-SymbolicName=" + artifact.getArtifactId() + "&Bundle-Version=" + artifact.getVersion().toString().replace("-", ".")+"&DynamicImport-Package=*"); //need improve the version processing InputStream in = null; try { in = wrap.openStream(); writeableRepo.copyToRepository(in, (int) libFile.getTotalSpace(), artifact, new RepoFileWriteMonitor()); } finally { if (in != null) in.close(); } } }
protected Artifact newArtifact(Artifact configId, String artifactId) { return new Artifact(configId.getGroupId(), artifactId, configId.getVersion(), configId.getType()); }
private Artifact resolve(Artifact configID) throws DeploymentException { String group = configID.getGroupId(); if (group == null) { group = Artifact.DEFAULT_GROUP_ID; } String artifactId = configID.getArtifactId(); if (artifactId == null) { throw new DeploymentException("Every configuration to deploy must have a ConfigID with an ArtifactID (not " + configID + ")"); } Version version = configID.getVersion(); if (version == null) { version = new Version(Long.toString(System.currentTimeMillis())); } String type = configID.getType(); if (type == null) { type = "car"; } return new Artifact(group, artifactId, version, type); }
/** * Translates the argument Artifact to a fully-resolved Artifact, which is * returned. If the argument was fully-resolved to begin with it is * returned as is. Otherwise, a new Artifact is returned with any missing * values populated. * * @param argument The artifact to review * @param defaultType The type to use if the artifact to review has no * type specified * * @return A fully resolved Artifact * * @throws IllegalArgumentException Occurs when the argument artifact does * not have an artifactId */ public Artifact resolve(Artifact argument, String defaultType) { if(argument.isResolved()) { return argument; } if(argument.getArtifactId() == null || argument.getArtifactId().equals("")) { throw new IllegalArgumentException("Incoming Artifact must have an ArtifactID (not "+argument+")"); } return new Artifact(argument.getGroupId() == null || argument.getGroupId().equals("") ? defaultGroup : argument.getGroupId(), argument.getArtifactId(), argument.getVersion() == null ? defaultVersion : argument.getVersion(), argument.getType() == null || argument.getType().equals("") ? defaultType : argument.getType()); }
public static ArtifactType toArtifactType(Artifact id) { ArtifactType artifact = new ArtifactType(); artifact.setGroupId(id.getGroupId()); artifact.setArtifactId(id.getArtifactId()); artifact.setVersion(id.getVersion() == null ? null : id.getVersion().toString()); artifact.setType(id.getType()); return artifact; }
private void populateDependency(DependencyType dep, String dependencyString) { Artifact artifact = Artifact.create(dependencyString.trim()); dep.setArtifactId(artifact.getArtifactId()); if (artifact.getGroupId() != null) { dep.setGroupId(artifact.getGroupId()); } if (artifact.getType() != null) { dep.setType(artifact.getType()); } if (artifact.getVersion() != null) { dep.setVersion(artifact.getVersion().toString()); } }
public JpaPluginInstance(String artifactUri) { Artifact artifact = Artifact.create(artifactUri); this.groupId = artifact.getGroupId(); this.artifactId = artifact.getArtifactId(); this.version = artifact.getVersion().toString(); this.type = artifact.getType(); }
public static DependencyType toDependencyType(Dependency dep, boolean includeVersion) { Artifact id = dep.getArtifact(); DependencyType dependency = new DependencyType(); dependency.setGroupId(id.getGroupId()); dependency.setArtifactId(id.getArtifactId()); if (includeVersion) { dependency.setVersion(id.getVersion() == null ? null : id.getVersion().toString()); } dependency.setType(id.getType()); return dependency; }
private static void fillArtifactType(Artifact artifact, ArtifactType artifactType) { if (artifact.getGroupId() != null) { artifactType.setGroupId(artifact.getGroupId()); } if (artifact.getArtifactId() != null) { artifactType.setArtifactId(artifact.getArtifactId()); } if (artifact.getVersion() != null) { artifactType.setVersion(artifact.getVersion().toString()); } if (artifact.getType() != null) { artifactType.setType(artifact.getType()); } }
@Override protected Name createBindingName(AbstractName abstractName, Object value) throws NamingException { String name = abstractName.getNameProperty("name"); if (namePattern != null) { Matcher matcher = namePattern.matcher(name); if (!matcher.matches()) { return null; } } Map<String, String> map = new HashMap<String, String>(abstractName.getName()); Artifact artifact = abstractName.getArtifact(); map.put("groupId", artifact.getGroupId()); map.put("artifactId", artifact.getArtifactId()); map.put("version", artifact.getVersion().toString()); map.put("type", artifact.getType()); String fullName = format(format, map); Name parsedName = getContext().getNameParser("").parse(getNameInNamespace()+"/" + fullName); // create intermediate contexts for (int i = 1; i < parsedName.size(); i++) { Name contextName = parsedName.getPrefix(i); if (!bindingExists(getContext(), contextName)) { getContext().createSubcontext(contextName); } } return parsedName; }
public PluginType getPlugin(Artifact sourceArtifact) { PluginType plugin = new PluginType(); PluginArtifactType pluginArtifact = new PluginArtifactType(); ArtifactType artifact = new ArtifactType(); artifact.setGroupId(sourceArtifact.getGroupId()); artifact.setArtifactId(sourceArtifact.getArtifactId()); artifact.setVersion(sourceArtifact.getVersion().toString()); artifact.setType(sourceArtifact.getType()); pluginArtifact.setModuleId(artifact); plugin.getPluginArtifact().add(pluginArtifact); return plugin; }
public static Bundle getRepositoryEntryBundle(PortletRequest request, String repositoryURI) { J2EEServer server = getCurrentServer(request); Artifact uri = Artifact.create(repositoryURI); if (!uri.isResolved()) { Artifact[] all = server.getConfigurationManager().getArtifactResolver().queryArtifacts(uri); if (all.length == 0) { return null; } else { uri = all[all.length - 1]; } } try { Kernel kernel = getKernel(); BundleContext bundleContext = kernel.getBundleFor(kernel.getKernelName()).getBundleContext(); //TODO Figure out who should be responsible for uninstalling it, and whether we need to start the bundle //Currently, this method is only used for resource reading, seems no need to start the bundle. return bundleContext.installBundle("mvn:" + uri.getGroupId() + "/" + uri.getArtifactId() + "/" + uri.getVersion() + ("jar".equals(uri.getType()) ? "" : "/" + uri.getType())); } catch (Exception e) { return null; } }
public void parseEnvironment(Environment env) { ArtifactType moduleId = environment.addNewModuleId(); Artifact configId = env.getConfigId(); moduleId.setGroupId(configId.getGroupId()); moduleId.setArtifactId(configId.getArtifactId()); moduleId.setVersion(configId.getVersion().toString()); moduleId.setType(configId.getType()); //List<Dependency> deps = env.getDependencies(); //for (int i = 0; i < deps.size(); i++) { // String depString = deps.get(i).toString(); // dependenciesSet.add(depString.substring(6, depString.length() - 1)); //} }