List of usage examples for org.apache.maven.artifact.repository Authentication Authentication
public Authentication(String userName, String password)
From source file:com.devexperts.bintray.BintrayDeployMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (skip)/*from www .j av a2 s . c om*/ return; // Create list of artifacts to be deployed. List<Artifact> artifacts = new ArrayList<>(); artifacts.add(project.getArtifact()); artifacts.addAll(project.getAttachedArtifacts()); // Create artifact repository. ArtifactRepository r = repositoryFactory.createDeploymentArtifactRepository(id, url, repositoryLayouts.get("default"), false); // Set authentication if user and key are passed to properties. if (user != null && key != null) r.setAuthentication(new Authentication(user, key)); // Deploy artifacts. for (Artifact a : artifacts) { try { File deployFile = a.getFile(); if (deployFile == null || !deployFile.exists()) deployFile = new File(buildDirectory + File.separator + finalName + "." + a.getType()); if (deployFile.exists()) { deploy(deployFile, a, r, getLocalRepository(), retryFailedDeploymentCount); } else { getLog().warn("Cannot deploy artifact " + a + ", no file to deploy"); } } catch (ArtifactDeploymentException e) { throw new MojoFailureException("Error occurred deploying the artifact", e); } } }
From source file:io.fabric8.maven.DeployToProfileMojo.java
License:Apache License
@SuppressWarnings("unchecked") protected void uploadDeploymentUnit(J4pClient client, boolean newUserAdded) throws Exception { String uri = getMavenUploadUri(client); // lets resolve the artifact to make sure we get a local file Artifact artifact = project.getArtifact(); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact);//from w w w.ja v a 2 s. co m addNeededRemoteRepository(); request.setRemoteRepositories(remoteRepositories); request.setLocalRepository(localRepository); resolver.resolve(request); String packaging = project.getPackaging(); File pomFile = project.getFile(); @SuppressWarnings("unchecked") List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); DefaultRepositoryLayout layout = new DefaultRepositoryLayout(); ArtifactRepository repo = new DefaultArtifactRepository(serverId, uri, layout); if (newUserAdded) { // make sure to set authentication if we just added new user repo.setAuthentication(new Authentication(fabricServer.getUsername(), fabricServer.getPassword())); } // Deploy the POM boolean isPomArtifact = "pom".equals(packaging); if (!isPomArtifact) { ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(metadata); } try { if (isPomArtifact) { deploy(pomFile, artifact, repo, localRepository, retryFailedDeploymentCount); } else { File file = artifact.getFile(); // lets deploy the pom for the artifact first if (isFile(pomFile)) { deploy(pomFile, artifact, repo, localRepository, retryFailedDeploymentCount); } if (isFile(file)) { deploy(file, artifact, repo, localRepository, retryFailedDeploymentCount); } else if (!attachedArtifacts.isEmpty()) { getLog().info("No primary artifact to deploy, deploying attached artifacts instead."); Artifact pomArtifact = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); pomArtifact.setFile(pomFile); deploy(pomFile, pomArtifact, repo, localRepository, retryFailedDeploymentCount); // propagate the timestamped version to the main artifact for the attached artifacts to pick it up artifact.setResolvedVersion(pomArtifact.getVersion()); } else { String message = "The packaging for this project did not assign a file to the build artifact"; throw new MojoExecutionException(message); } } for (Artifact attached : attachedArtifacts) { deploy(attached.getFile(), attached, repo, localRepository, retryFailedDeploymentCount); } } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.appformer.maven.integration.MavenRepositoryConfiguration.java
License:Apache License
private ArtifactRepository toArtifactRepository(RemoteRepository remoteRepository) { final String id = remoteRepository.getId(); final String url = remoteRepository.getUrl(); final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy(); ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy(); if (remoteRepository.getPolicy(true) != null) { snapshots = new ArtifactRepositoryPolicy(remoteRepository.getPolicy(true).isEnabled(), remoteRepository.getPolicy(true).getUpdatePolicy(), remoteRepository.getPolicy(true).getChecksumPolicy()); }//from w w w . j a v a 2s .c om if (remoteRepository.getPolicy(false) != null) { releases = new ArtifactRepositoryPolicy(remoteRepository.getPolicy(false).isEnabled(), remoteRepository.getPolicy(false).getUpdatePolicy(), remoteRepository.getPolicy(false).getChecksumPolicy()); } final ArtifactRepository artifactRepository = new MavenArtifactRepository(id, url, layout, snapshots, releases); final Server server = settings.getServer(id); if (server != null) { artifactRepository.setAuthentication(new Authentication(server.getUsername(), server.getPassword())); } return artifactRepository; }
From source file:org.fusesource.mop.MOPRepository.java
License:Open Source License
/** * Adds some default remote repositories * // w ww . j a v a 2 s. co m * @param repositorySystem */ protected List<ArtifactRepository> createRemoteRepositories(RepositorySystem repositorySystem) { List<ArtifactRepository> rc = new ArrayList<ArtifactRepository>(); String mavenRepositoryDir = System.getProperty("user.home", ".") + "/.m2/repository"; rc.add(createLocalRepository(repositorySystem, RepositorySystem.DEFAULT_LOCAL_REPO_ID, mavenRepositoryDir, true)); DefaultRepositoryLayout layout = new DefaultRepositoryLayout(); ArtifactRepositoryPolicy repositoryPolicy = new ArtifactRepositoryPolicy(); if (online) { repositoryPolicy.setUpdatePolicy(updatePolicy); } else { repositoryPolicy.setUpdatePolicy(ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER); } for (Map.Entry<String, String> entry : remoteRepositories.entrySet()) { String repoUrl = entry.getValue(); //Let's strip the username password out so that it doesn't get displayed: Authentication auth = null; try { URL url = new URL(entry.getValue().toString()); String userInfo = url.getUserInfo(); if (userInfo != null) { StringTokenizer tok = new StringTokenizer(userInfo, ":"); if (tok.countTokens() == 1) { auth = new Authentication(userInfo, null); } else if (tok.countTokens() == 2) { auth = new Authentication(tok.nextToken(), tok.nextToken()); } else if (tok.countTokens() > 2) { auth = new Authentication(tok.nextToken(), userInfo.substring(userInfo.indexOf(":") + 1)); } repoUrl = url.getProtocol() + "://" + repoUrl.substring(repoUrl.indexOf("@") + 1); } } catch (MalformedURLException e) { warn("Invalid Repository url for: " + entry.getKey() + ": " + entry.getValue()); } ArtifactRepository ar = repositorySystem.createArtifactRepository(entry.getKey(), repoUrl, layout, repositoryPolicy, repositoryPolicy); if (auth != null) { ar.setAuthentication(auth); } rc.add(ar); } return rc; }