Search in sources :

Example 1 with ResourceDoesNotExistException

use of org.apache.maven.wagon.ResourceDoesNotExistException in project wagon-git by synergian.

the class GitWagon method fillInputData.

/**
	 * {@inheritDoc}
	 */
public void fillInputData(InputData inputData) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    log.debug("Invoked fillInputData()");
    Resource resource = inputData.getResource();
    File file = new File(git.workDir, resource.getName());
    if (!file.exists()) {
        throw new ResourceDoesNotExistException("File: " + file + " does not exist");
    }
    try {
        InputStream in = new BufferedInputStream(new FileInputStream(file));
        inputData.setInputStream(in);
        resource.setContentLength(file.length());
        resource.setLastModified(file.lastModified());
    } catch (FileNotFoundException e) {
        throw new TransferFailedException("Could not read from file: " + file.getAbsolutePath(), e);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Resource(org.apache.maven.wagon.resource.Resource) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) FileInputStream(java.io.FileInputStream)

Example 2 with ResourceDoesNotExistException

use of org.apache.maven.wagon.ResourceDoesNotExistException in project gradle by gradle.

the class RepositoryTransportDeployWagon method get.

@Override
public final void get(String resourceName, File destination) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    Resource resource = new Resource(resourceName);
    this.transferEventSupport.fireTransferInitiated(transferEvent(resource, TRANSFER_INITIATED, REQUEST_GET));
    this.transferEventSupport.fireTransferStarted(transferEvent(resource, TRANSFER_STARTED, REQUEST_GET));
    try {
        if (!destination.exists()) {
            destination.getParentFile().mkdirs();
            destination.createNewFile();
        }
        if (!getDelegate().getRemoteFile(destination, resourceName)) {
            throw new ResourceDoesNotExistException(String.format("Resource '%s' does not exist", resourceName));
        }
        this.transferEventSupport.fireTransferCompleted(transferEvent(resource, TRANSFER_COMPLETED, REQUEST_GET));
    } catch (ResourceDoesNotExistException e) {
        this.transferEventSupport.fireTransferError(transferEvent(resource, e, REQUEST_GET));
        throw e;
    } catch (Exception e) {
        this.transferEventSupport.fireTransferError(transferEvent(resource, e, REQUEST_GET));
        throw new TransferFailedException(String.format("Could not get resource '%s'", resourceName), e);
    }
}
Also used : Resource(org.apache.maven.wagon.resource.Resource) LocalResource(org.gradle.internal.resource.local.LocalResource) FileLocalResource(org.gradle.internal.resource.local.FileLocalResource) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) IOException(java.io.IOException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) GradleException(org.gradle.api.GradleException) TransferFailedException(org.apache.maven.wagon.TransferFailedException)

Example 3 with ResourceDoesNotExistException

use of org.apache.maven.wagon.ResourceDoesNotExistException in project maven-plugins by apache.

the class DefaultRepositoryCopier method copy.

public void copy(Repository sourceRepository, Repository targetRepository, String version) throws WagonException, IOException {
    String prefix = "staging-plugin";
    String fileName = prefix + "-" + version + ".zip";
    String tempdir = System.getProperty("java.io.tmpdir");
    logger.debug("Writing all output to " + tempdir);
    // Create the renameScript script
    String renameScriptName = prefix + "-" + version + "-rename.sh";
    File renameScript = new File(tempdir, renameScriptName);
    // Work directory
    File basedir = new File(tempdir, prefix + "-" + version);
    FileUtils.deleteDirectory(basedir);
    basedir.mkdirs();
    Wagon sourceWagon = wagonManager.getWagon(sourceRepository);
    AuthenticationInfo sourceAuth = wagonManager.getAuthenticationInfo(sourceRepository.getId());
    sourceWagon.connect(sourceRepository, sourceAuth);
    logger.info("Looking for files in the source repository.");
    List<String> files = new ArrayList<String>();
    scan(sourceWagon, "", files);
    logger.info("Downloading files from the source repository to: " + basedir);
    for (String s : files) {
        if (s.contains(".svn")) {
            continue;
        }
        File f = new File(basedir, s);
        FileUtils.mkdir(f.getParentFile().getAbsolutePath());
        logger.info("Downloading file from the source repository: " + s);
        sourceWagon.get(s, f);
    }
    // ----------------------------------------------------------------------------
    // Now all the files are present locally and now we are going to grab the
    // metadata files from the targetRepositoryUrl and pull those down locally
    // so that we can merge the metadata.
    // ----------------------------------------------------------------------------
    logger.info("Downloading metadata from the target repository.");
    Wagon targetWagon = wagonManager.getWagon(targetRepository);
    if (!(targetWagon instanceof CommandExecutor)) {
        throw new CommandExecutionException("Wagon class '" + targetWagon.getClass().getName() + "' in use for target repository is not a CommandExecutor");
    }
    AuthenticationInfo targetAuth = wagonManager.getAuthenticationInfo(targetRepository.getId());
    targetWagon.connect(targetRepository, targetAuth);
    PrintWriter rw = new PrintWriter(new FileWriter(renameScript));
    File archive = new File(tempdir, fileName);
    for (String s : files) {
        if (s.startsWith("/")) {
            s = s.substring(1);
        }
        if (s.endsWith(MAVEN_METADATA)) {
            File emf = new File(basedir, s + IN_PROCESS_MARKER);
            try {
                targetWagon.get(s, emf);
            } catch (ResourceDoesNotExistException e) {
                continue;
            }
            try {
                mergeMetadata(emf);
            } catch (XmlPullParserException e) {
                throw new IOException("Metadata file is corrupt " + s + " Reason: " + e.getMessage());
            }
        }
    }
    Set moveCommands = new TreeSet();
    // ----------------------------------------------------------------------------
    // Create the Zip file that we will deploy to the targetRepositoryUrl stage
    // ----------------------------------------------------------------------------
    logger.info("Creating zip file.");
    OutputStream os = new FileOutputStream(archive);
    ZipOutputStream zos = new ZipOutputStream(os);
    scanDirectory(basedir, basedir, zos, version, moveCommands);
    // ----------------------------------------------------------------------------
    // Create the renameScript script. This is as atomic as we can
    // ----------------------------------------------------------------------------
    logger.info("Creating rename script.");
    for (Object moveCommand : moveCommands) {
        String s = (String) moveCommand;
        // We use an explicit unix '\n' line-ending here instead of using the println() method.
        // Using println() will cause files and folders to have a '\r' at the end if the plugin is run on Windows.
        rw.print(s + "\n");
    }
    rw.close();
    ZipEntry e = new ZipEntry(renameScript.getName());
    zos.putNextEntry(e);
    InputStream is = new FileInputStream(renameScript);
    IOUtil.copy(is, zos);
    zos.close();
    is.close();
    sourceWagon.disconnect();
    // Push the Zip to the target system
    logger.info("Uploading zip file to the target repository.");
    targetWagon.put(archive, fileName);
    logger.info("Unpacking zip file on the target machine.");
    String targetRepoBaseDirectory = targetRepository.getBasedir();
    // We use the super quiet option here as all the noise seems to kill/stall the connection
    String command = "unzip -o -qq -d " + targetRepoBaseDirectory + " " + targetRepoBaseDirectory + "/" + fileName;
    ((CommandExecutor) targetWagon).executeCommand(command);
    logger.info("Deleting zip file from the target repository.");
    command = "rm -f " + targetRepoBaseDirectory + "/" + fileName;
    ((CommandExecutor) targetWagon).executeCommand(command);
    logger.info("Running rename script on the target machine.");
    command = "cd " + targetRepoBaseDirectory + "; sh " + renameScriptName;
    ((CommandExecutor) targetWagon).executeCommand(command);
    logger.info("Deleting rename script from the target repository.");
    command = "rm -f " + targetRepoBaseDirectory + "/" + renameScriptName;
    ((CommandExecutor) targetWagon).executeCommand(command);
    targetWagon.disconnect();
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) CommandExecutor(org.apache.maven.wagon.CommandExecutor) Wagon(org.apache.maven.wagon.Wagon) IOException(java.io.IOException) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) FileInputStream(java.io.FileInputStream) TreeSet(java.util.TreeSet) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) CommandExecutionException(org.apache.maven.wagon.CommandExecutionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) File(java.io.File) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) PrintWriter(java.io.PrintWriter)

Example 4 with ResourceDoesNotExistException

use of org.apache.maven.wagon.ResourceDoesNotExistException in project gradle by gradle.

the class RepositoryTransportDeployWagon method put.

@Override
public final void put(File file, String resourceName) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    Resource resource = new Resource(resourceName);
    this.transferEventSupport.fireTransferInitiated(transferEvent(resource, TRANSFER_INITIATED, REQUEST_PUT));
    try {
        LocalResource localResource = new MavenTransferLoggingFileResource(file, resource);
        getDelegate().putRemoteFile(localResource, resourceName);
    } catch (Exception e) {
        this.transferEventSupport.fireTransferError(transferEvent(resource, e, REQUEST_PUT));
        throw new TransferFailedException(String.format("Could not write to resource '%s'", resourceName), e);
    }
    this.transferEventSupport.fireTransferCompleted(transferEvent(resource, TRANSFER_COMPLETED, REQUEST_PUT));
}
Also used : Resource(org.apache.maven.wagon.resource.Resource) LocalResource(org.gradle.internal.resource.local.LocalResource) FileLocalResource(org.gradle.internal.resource.local.FileLocalResource) TransferFailedException(org.apache.maven.wagon.TransferFailedException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) IOException(java.io.IOException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) GradleException(org.gradle.api.GradleException) TransferFailedException(org.apache.maven.wagon.TransferFailedException) LocalResource(org.gradle.internal.resource.local.LocalResource) FileLocalResource(org.gradle.internal.resource.local.FileLocalResource)

Example 5 with ResourceDoesNotExistException

use of org.apache.maven.wagon.ResourceDoesNotExistException in project maven-plugins by apache.

the class AbstractDeployMojo method push.

private void push(final File inputDirectory, final Repository repository, final Wagon wagon, final ProxyInfo proxyInfo, final List<Locale> localesList, final String relativeDir) throws MojoExecutionException {
    AuthenticationInfo authenticationInfo = wagonManager.getAuthenticationInfo(repository.getId());
    getLog().debug("authenticationInfo with id '" + repository.getId() + "': " + ((authenticationInfo == null) ? "-" : authenticationInfo.getUserName()));
    try {
        if (getLog().isDebugEnabled()) {
            Debug debug = new Debug();
            wagon.addSessionListener(debug);
            wagon.addTransferListener(debug);
        }
        if (proxyInfo != null) {
            getLog().debug("connect with proxyInfo");
            wagon.connect(repository, authenticationInfo, proxyInfo);
        } else if (proxyInfo == null && authenticationInfo != null) {
            getLog().debug("connect with authenticationInfo and without proxyInfo");
            wagon.connect(repository, authenticationInfo);
        } else {
            getLog().debug("connect without authenticationInfo and without proxyInfo");
            wagon.connect(repository);
        }
        getLog().info("Pushing " + inputDirectory);
        // Default is first in the list
        final String defaultLocale = localesList.get(0).getLanguage();
        for (Locale locale : localesList) {
            if (locale.getLanguage().equals(defaultLocale)) {
                // TODO: this also uploads the non-default locales,
                // is there a way to exclude directories in wagon?
                getLog().info("   >>> to " + repository.getUrl() + relativeDir);
                wagon.putDirectory(inputDirectory, relativeDir);
            } else {
                getLog().info("   >>> to " + repository.getUrl() + locale.getLanguage() + "/" + relativeDir);
                wagon.putDirectory(new File(inputDirectory, locale.getLanguage()), locale.getLanguage() + "/" + relativeDir);
            }
        }
    } catch (ResourceDoesNotExistException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (TransferFailedException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (AuthorizationException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (ConnectionException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (AuthenticationException e) {
        throw new MojoExecutionException("Error uploading site", e);
    }
}
Also used : Locale(java.util.Locale) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) File(java.io.File) TransferFailedException(org.apache.maven.wagon.TransferFailedException) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) Debug(org.apache.maven.wagon.observers.Debug) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) ConnectionException(org.apache.maven.wagon.ConnectionException)

Aggregations

ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)5 TransferFailedException (org.apache.maven.wagon.TransferFailedException)4 File (java.io.File)3 IOException (java.io.IOException)3 ConnectionException (org.apache.maven.wagon.ConnectionException)3 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)3 AuthorizationException (org.apache.maven.wagon.authorization.AuthorizationException)3 Resource (org.apache.maven.wagon.resource.Resource)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)2 GradleException (org.gradle.api.GradleException)2 FileLocalResource (org.gradle.internal.resource.local.FileLocalResource)2 LocalResource (org.gradle.internal.resource.local.LocalResource)2 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1