List of usage examples for org.apache.maven.artifact.repository ArtifactRepository getProtocol
String getProtocol();
From source file:com.savage7.maven.plugin.dependency.DeployExternalDependencyMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { // update base configuration parameters // (not sure why this is needed, but doesn't see to work otherwise?) super.localRepository = this.localRepository; getLog().info("starting to deploy external dependencies to distribution repository"); // loop over and process all configured artifacts for (ArtifactItem artifactItem : artifactItems) { getLog().info("resolving artifact in locale repository for deployment: " + artifactItem.toString()); ////from ww w . jav a 2s. c o m // CREATE MAVEN ARTIFACT // Artifact artifact = createArtifact(artifactItem); // determine if the artifact is already installed in the local Maven // repository File installedArtifactFile = getLocalRepoFile(artifact); // only proceed with this artifact if it is not already // installed or it is configured to be forced. if (installedArtifactFile.exists()) { try { artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); // // DEPLOY TO DISTRIBUTION MAVEN REPOSITORY // if (artifactItem.getDeploy()) { failIfOffline(); ArtifactRepository repo = getDeploymentRepository(); String protocol = repo.getProtocol(); if (protocol.equalsIgnoreCase("scp")) { File sshFile = new File(System.getProperty("user.home"), ".ssh"); if (!sshFile.exists()) { sshFile.mkdirs(); } } // create Maven artifact POM file File generatedPomFile = null; // don't generate a POM file for POM artifacts if (!"pom".equals(artifactItem.getPackaging())) { // if a POM file was provided for the artifact item, // then // use that POM file instead of generating a new one if (artifactItem.getPomFile() != null) { ArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, artifactItem.getPomFile()); artifact.addMetadata(pomMetadata); } else { // dynamically create a new POM file for this // artifact generatedPomFile = generatePomFile(artifactItem); ArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, generatedPomFile); if (artifactItem.getGeneratePom() == true) { artifact.addMetadata(pomMetadata); } } } // deploy now getLog().info("deploying artifact to distribution repository: " + artifactItem.toString()); artifactDeployer.deploy(artifact.getFile(), artifact, repo, localRepository); //TODO Deploy Checksums? } else { getLog().debug("configured to not deploy artifact: " + artifactItem.toString()); } } catch (MojoFailureException e) { throw e; } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Error occurred while attempting to resolve artifact.", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to find external dependency in local repository.", e); } catch (ArtifactDeploymentException e) { throw new MojoExecutionException("Deployment of external dependency failed.", e); } } else { // throw error because we were unable to find the installed // external dependency try { throw new MojoFailureException("Unable to find external dependency '" + artifactItem.getArtifactId() + "'; file not found in local repository: " + installedArtifactFile.getCanonicalPath()); } catch (IOException e) { throw new MojoExecutionException("Unable to resolve dependency path in locale repository.", e); } } } getLog().info("finished deploying external dependencies to distribution repository"); }
From source file:com.universalmediaserver.external.DeployExternalDependencyMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); getLog().info("Starting to deploy external dependencies to distribution repository"); // Loop over and process all configured artifacts for (ArtifactItem artifactItem : artifactItems) { getLog().info("Resolving artifact in locale repository for deployment: " + artifactItem.toString()); // Create Maven artifact Artifact artifact = createArtifact(artifactItem); // Determine if the artifact is already installed in the local Maven repository File installedArtifactFile = getLocalRepoFile(artifact); // Only proceed with this artifact if it is installed in the local repository. if (installedArtifactFile.exists()) { if (!resolveArtifactItem(artifact)) { throw new MojoExecutionException("Could not resolve artifact " + artifact.toString() + NEWLINE + "Make sure \"resolve\" and \"install\" goals has been executed first"); }//from w ww .j ava 2 s . co m // Deploy to distribution Maven repository if (artifactItem.getDeploy()) { ArtifactRepository repo = getDeploymentRepository(); String protocol = repo.getProtocol(); if (protocol.equalsIgnoreCase("scp")) { File sshFolder = new File(System.getProperty("user.home"), ".ssh"); if (!sshFolder.exists() && !sshFolder.mkdirs()) { throw new MojoExecutionException( "Could not create folder: " + sshFolder.getAbsolutePath()); } } // Create Maven artifact POM file File generatedPomFile = null; // Don't generate a POM file for POM artifacts if (!"pom".equals(artifactItem.getPackaging())) { if (artifactItem.getPomFile() != null) { /* * If a POM file was provided for the artifact * item, then use that POM file instead of * generating a new one */ ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, artifactItem.getPomFile()); artifact.addMetadata(pomMetadata); } else { // Dynamically create a new POM file for this artifact generatedPomFile = generatePomFile(artifactItem); ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, generatedPomFile); if (artifactItem.getGeneratePom() == true) { artifact.addMetadata(pomMetadata); } } } // Deploy now getLog().info("Deploying artifact to distribution repository: " + artifactItem.toString()); try { artifactDeployer.deploy(artifact.getFile(), artifact, repo, localRepository); } catch (ArtifactDeploymentException e) { throw new MojoExecutionException( "Deployment of external dependency failed with: " + e.getMessage(), e); } } else { getLog().debug("Configured to not deploy artifact: " + artifactItem.toString()); } } else { // Throw exception because we were unable to find the installed external dependency throw new MojoExecutionException("Unable to find external dependency \"" + artifactItem.getArtifactId() + "\"; file not found in local repository: " + installedArtifactFile.getAbsolutePath()); } } getLog().info("Finished deploying external dependencies to distribution repository"); }
From source file:com.webcohesion.enunciate.mojo.DeployArtifactBaseMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (this.enunciateArtifactId == null) { throw new MojoExecutionException("An enunciate artifact id must be supplied."); }/*from w w w . j av a 2 s. c om*/ Enunciate enunciate = (Enunciate) getPluginContext().get(ConfigMojo.ENUNCIATE_PROPERTY); if (enunciate == null) { throw new MojoExecutionException("No enunciate mechanism found in the project!"); } com.webcohesion.enunciate.artifacts.Artifact enunciateArtifact = enunciate .findArtifact(this.enunciateArtifactId); if (enunciateArtifact == null) { throw new MojoExecutionException("Unknown Enunciate artifact: " + this.enunciateArtifactId + "."); } File mainArtifact = null; File sources = null; File javadocs = null; if (enunciateArtifact instanceof ClientLibraryArtifact) { for (com.webcohesion.enunciate.artifacts.Artifact childArtifact : ((ClientLibraryArtifact) enunciateArtifact) .getArtifacts()) { if (childArtifact instanceof FileArtifact) { ArtifactType artifactType = ((FileArtifact) childArtifact).getArtifactType(); if (artifactType != null) { switch (artifactType) { case binaries: mainArtifact = ((FileArtifact) childArtifact).getFile(); break; case sources: sources = ((FileArtifact) childArtifact).getFile(); break; case javadocs: javadocs = ((FileArtifact) childArtifact).getFile(); break; } } } } } else if (enunciateArtifact instanceof FileArtifact) { mainArtifact = ((FileArtifact) enunciateArtifact).getFile(); } else { try { mainArtifact = enunciate.createTempFile(this.enunciateArtifactId, "artifact"); enunciateArtifact.exportTo(mainArtifact, enunciate); } catch (IOException e) { throw new MojoExecutionException("Unable to create a temp file.", e); } } if (mainArtifact == null) { if (sources != null) { mainArtifact = sources; sources = null; } } if (mainArtifact == null) { throw new MojoExecutionException( "Unable to determine the file to deploy from enunciate artifact " + enunciateArtifactId + "."); } // Process the supplied POM (if there is one) Model model = null; if (pomFile != null) { generatePom = false; model = readModel(pomFile); processModel(model); } if (this.packaging == null) { String artifactName = mainArtifact.getName(); int dotIndex = artifactName.indexOf('.'); if (dotIndex > 0 && (dotIndex + 1 < artifactName.length())) { this.packaging = artifactName.substring(dotIndex + 1); } } if (this.packaging == null) { throw new MojoExecutionException("Unable to determine the packaging of enunciate artifact " + enunciateArtifactId + ". Please specify it in the configuration."); } if (this.version == null) { throw new MojoExecutionException("Null version."); } if (model == null) { model = new Model(); model.setModelVersion("4.0.0"); model.setGroupId(this.groupId); model.setArtifactId(this.artifactId); model.setVersion(this.version); model.setPackaging(this.packaging); model.setDescription(this.description); } ArtifactRepository repo = getDeploymentRepository(); String protocol = repo.getProtocol(); if (protocol.equals("scp")) { File sshFile = new File(System.getProperty("user.home"), ".ssh"); if (!sshFile.exists()) { sshFile.mkdirs(); } } Artifact artifact = this.artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier); // Upload the POM if requested, generating one if need be if (generatePom) { ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, generatePomFile(model)); artifact.addMetadata(metadata); } else { ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(metadata); } try { getDeployer().deploy(mainArtifact, artifact, repo, this.localRepository); if (sources != null || javadocs != null) { MavenProject project = new MavenProject(model); project.setArtifact(artifact); if (sources != null) { //we have to do it this way because of classloading issues. this.projectHelper.attachArtifact(project, artifact.getType(), "sources", sources); getDeployer().deploy(sources, (Artifact) project.getAttachedArtifacts().get(0), repo, this.localRepository); } if (javadocs != null) { //we have to do it this way because of classloading issues. this.projectHelper.attachArtifact(project, artifact.getType(), "javadoc", javadocs); getDeployer().deploy(javadocs, (Artifact) project.getAttachedArtifacts().get(0), repo, this.localRepository); } } } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:hudson.staging.SCPRepositoryCopier.java
License:Apache License
protected List scanForArtifactPaths(ArtifactRepository repository) { List collected;//from w ww .j a v a 2 s .com try { Wagon wagon = wagonManager.getWagon(repository.getProtocol()); Repository artifactRepository = new Repository(repository.getId(), repository.getUrl()); wagon.connect(artifactRepository); collected = new ArrayList(); scan(wagon, "/", collected); wagon.disconnect(); return collected; } catch (UnsupportedProtocolException e) { throw new RuntimeException(e); } catch (ConnectionException e) { throw new RuntimeException(e); } catch (AuthenticationException e) { throw new RuntimeException(e); } }
From source file:lu.softec.maven.mavenizer.FileDeployerMojo.java
License:Open Source License
public void deployFile(MavenFile mvnFile) throws MojoExecutionException, MojoFailureException { ArtifactRepositoryLayout layout = getLayout(repositoryLayout); ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository(repositoryId, repositoryUrl, layout, uniqueVersion); String protocol = deploymentRepository.getProtocol(); if (StringUtils.isEmpty(protocol)) { throw new MojoExecutionException("No transfer protocol found."); }/*from w ww .ja v a 2 s.c o m*/ // Create the artifact Artifact artifact = artifactFactory.createArtifactWithClassifier(mvnFile.getGroupId(), mvnFile.getArtifactId(), mvnFile.getVersion(), mvnFile.getPackaging(), mvnFile.getClassifier()); if (mvnFile.getFile().equals(getLocalRepoFile(artifact))) { throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + mvnFile.getFile()); } File pomFile = getPomFile(mvnFile); if (!pomFile.exists()) { throw new MojoExecutionException("No POM file found for: " + mvnFile.getFile()); } ArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(pomMetadata); if (updateReleaseInfo) { artifact.setRelease(true); } try { deployer.deploy(mvnFile.getFile(), artifact, deploymentRepository, getLocalRepository()); } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:npanday.plugin.libraryimporter.deploy.AbstractDeployMojo.java
License:Apache License
@Override protected void innerExecute() throws MojoExecutionException, MojoFailureException { if (skip) {/*from w ww . java 2s . c om*/ getLog().info("NPANDAY-147-008: deploying imported libraries was explicitely skipped"); return; } failIfOffline(); ArtifactRepository repo = getDeploymentRepository(); String protocol = repo.getProtocol(); if (protocol.equalsIgnoreCase("scp")) { File sshFile = new File(System.getProperty("user.home"), ".ssh"); if (!sshFile.exists()) { sshFile.mkdirs(); } } super.innerExecute(); }
From source file:org.codehaus.mojo.repositorytools.discoverer.WagonDiscoverer.java
protected List scanForArtifactPaths(ArtifactRepository repository, List blacklistedPatterns, String[] includes, String[] excludes) {//from w w w . j av a2 s. c om List collected; try { Wagon wagon = wagonManager.getWagon(repository.getProtocol()); Repository artifactRepository = new Repository(repository.getId(), repository.getUrl()); wagon.connect(artifactRepository); collected = new ArrayList(); scan(wagon, "/", collected); wagon.disconnect(); return collected; } catch (UnsupportedProtocolException e) { throw new RuntimeException(e); } catch (ConnectionException e) { throw new RuntimeException(e); } catch (AuthenticationException e) { throw new RuntimeException(e); } }
From source file:org.jetbrains.idea.maven.server.Maven3ServerIndexFetcher.java
License:Apache License
@Override public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException { ArtifactRepository artifactRepository = myRepositorySystem.createArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null, null, null); final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(artifactRepository); String mirrorUrl = mirrorRepository.getUrl(); String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index"; Repository repository = new Repository(myOriginalRepositoryId, indexUrl); try {/*from w w w. j a va 2s . co m*/ myWagon = myWagonManager.getWagon(repository); myWagon.addTransferListener(myListener); myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol())); } catch (AuthenticationException e) { IOException newEx = new IOException("Authentication exception connecting to " + repository); newEx.initCause(e); throw newEx; } catch (WagonException e) { IOException newEx = new IOException("Wagon exception connecting to " + repository); newEx.initCause(e); throw newEx; } }
From source file:org.objectstyle.woproject.maven2.wobootstrap.BootstrapDeployMojo.java
License:Open Source License
/** * This method allows the deployment of the given artifact into a remote * Maven repository./* w w w . j a v a2 s. c o m*/ * * @see AbstractBootstrapMojo#executeGoal(File, Artifact) */ @Override protected void executeGoal(File file, Artifact artifact) throws MojoExecutionException { ArtifactRepositoryLayout layout; layout = (ArtifactRepositoryLayout) repositoryLayouts.get("default"); ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository(repositoryId, url, layout, false); String protocol = deploymentRepository.getProtocol(); if (protocol == null || "".equals(protocol)) { throw new MojoExecutionException("No transfer protocol found."); } try { deployer.deploy(file, artifact, deploymentRepository, localRepository); } catch (ArtifactDeploymentException exception) { throw new MojoExecutionException("Error while trying to deploy the artifact.", exception); } }
From source file:org.org.maven.plugin.dws.utils.RepositoryUtils.java
License:Apache License
/** * @param repo not null// w ww. j a v a 2 s.co m * @param artifact not null * @return <code>true</code> if the artifact exists in the given repo, <code>false</code> otherwise or if * the repo is blacklisted. */ public boolean dependencyExistsInRepo(ArtifactRepository repo, Artifact artifact) { if (repo.isBlacklisted()) { if (log.isDebugEnabled()) { log.debug("The repo '" + repo.getId() + "' is black listed - Ignored it"); } return false; } String id = repo.getId(); Repository repository = new Repository(id, repo.getUrl()); Wagon wagon; try { wagon = wagonManager.getWagon(repository); } catch (UnsupportedProtocolException e) { log.error("Unsupported protocol: '" + repo.getProtocol() + "'", e); return false; } catch (WagonConfigurationException e) { log.error("Unsupported protocol: '" + repo.getProtocol() + "'", e); return false; } if (log.isDebugEnabled()) { Debug debug = new Debug(); wagon.addSessionListener(debug); wagon.addTransferListener(debug); } try { AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId()); ProxyInfo proxyInfo = getProxyInfo(); if (proxyInfo != null) { wagon.connect(repository, auth, proxyInfo); } else { wagon.connect(repository, auth); } return wagon.resourceExists( StringUtils.replace(getDependencyUrlFromRepository(artifact, repo), repo.getUrl(), "")); } catch (ConnectionException e) { if (log.isDebugEnabled()) { log.error("Unable to connect to: " + repo.getUrl(), e); } else { log.error("Unable to connect to: " + repo.getUrl()); } return false; } catch (AuthenticationException e) { if (log.isDebugEnabled()) { log.error("Unable to connect to: " + repo.getUrl(), e); } else { log.error("Unable to connect to: " + repo.getUrl()); } return false; } catch (TransferFailedException e) { if (log.isDebugEnabled()) { log.error("Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e); } else { log.error("Unable to determine if resource " + artifact + " exists in " + repo.getUrl()); } return false; } catch (AuthorizationException e) { if (log.isDebugEnabled()) { log.error("Unable to connect to: " + repo.getUrl(), e); } else { log.error("Unable to connect to: " + repo.getUrl()); } return false; } catch (AbstractMethodError e) { log.error("Wagon " + wagon.getClass().getName() + " does not support the resourceExists method"); return false; } finally { try { wagon.disconnect(); } catch (ConnectionException e) { if (log.isDebugEnabled()) { log.error("Error disconnecting wagon - ignored", e); } else { log.error("Error disconnecting wagon - ignored"); } } } }