Example usage for org.apache.maven.artifact.metadata ArtifactMetadata getRemoteFilename

List of usage examples for org.apache.maven.artifact.metadata ArtifactMetadata getRemoteFilename

Introduction

In this page you can find the example usage for org.apache.maven.artifact.metadata ArtifactMetadata getRemoteFilename.

Prototype

String getRemoteFilename();

Source Link

Document

Get the filename of this metadata on the remote repository.

Usage

From source file:org.apache.archiva.converter.artifact.LegacyRepositoryLayout.java

License:Apache License

@Override
public String pathOfRemoteRepositoryMetadata(ArtifactMetadata metadata) {
    return pathOfRepositoryMetadata(metadata, metadata.getRemoteFilename());
}

From source file:org.codehaus.mojo.appassembler.repository.FlatRepositoryLayout.java

License:Open Source License

public String pathOfRemoteRepositoryMetadata(ArtifactMetadata metadata) {
    return pathOfRepositoryMetadata(metadata.getRemoteFilename());
}

From source file:org.universaal.tools.buildserviceapplication.actions.UploadArtifact.java

License:Apache License

private void postMetadata() {

    Iterator<ArtifactMetadata> it = BuildAction.artifactMetadata.get(getSelectedMavenProject()).iterator();
    while (it.hasNext()) {
        ArtifactMetadata metadata = it.next();
        try {//from  w  w w .  jav a2  s .co  m
            String webPage = "";
            if (metadata.getRemoteFilename().endsWith(".pom")) {
                if (isArtifactRelease) {
                    webPage = NEXUS_URL + "releases/" + groupId.replace(".", "/") + "/" + artifactId + "/"
                            + artifactVersion + "/" + metadata.getRemoteFilename();
                } else {
                    webPage = NEXUS_URL + "snapshots/" + groupId.replace(".", "/") + "/" + artifactId + "/"
                            + artifactVersion + "/" + metadata.getRemoteFilename();
                }
            } else {
                if (isArtifactRelease) {
                    webPage = NEXUS_URL + "releases/" + groupId.replace(".", "/") + "/" + artifactId + "/"
                            + metadata.getRemoteFilename();
                } else {
                    webPage = NEXUS_URL + "snapshots/" + groupId.replace(".", "/") + "/" + artifactId + "/"
                            + metadata.getRemoteFilename();
                }
            }

            String authString = NEXUS_USERNAME + ":" + NEXUS_PASSWORD;
            byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
            String authStringEnc = new String(authEncBytes);

            URL url = new URL(webPage);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
            urlConnection.setDoOutput(true);
            urlConnection.setRequestMethod("PUT");

            OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
            File file = null;
            if (metadata.getRemoteFilename().endsWith(".pom")) {
                file = new File(repositoryPath + File.separator + "repository" + File.separator
                        + groupId.replace(".", File.separator) + File.separator + artifactId + File.separator
                        + artifactVersion + File.separator + metadata.getRemoteFilename());
            } else {
                file = new File(repositoryPath + File.separator + "repository" + File.separator
                        + groupId.replace(".", File.separator) + File.separator + artifactId + File.separator
                        + "maven-metadata-local.xml");
            }

            FileInputStream fis = new FileInputStream(file);
            char current;
            while (fis.available() > 0) {
                current = (char) fis.read();
                out.write(current);
            }

            out.close();
            InputStream is = urlConnection.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            int numCharsRead = 0;
            char[] charArray = new char[1024];
            StringBuffer sb = new StringBuffer();
            while ((numCharsRead = isr.read(charArray)) > 0) {
                sb.append(charArray, 0, numCharsRead);
            }
        } catch (Exception ex) {
            artifactUploaded = false;
            ex.printStackTrace();
        }
    }
}