You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2018/09/10 06:17:16 UTC

[GitHub] robseidel commented on issue #1: fix DeployAtEnd failures

robseidel commented on issue #1: fix DeployAtEnd failures
URL: https://github.com/apache/maven-deploy-plugin/pull/1#issuecomment-419800283
 
 
   As I've written before, this PR can be fixed without breaking other stuff by using any form of serialization:
   
   Just use the following class:
   
   DeployRequestList
   
   package org.apache.maven.plugin.deploy;
   
   import java.beans.XMLDecoder;
   import java.beans.XMLEncoder;
   import java.io.BufferedInputStream;
   import java.io.BufferedOutputStream;
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.Serializable;
   import java.nio.charset.StandardCharsets;
   import java.util.ArrayList;
   import java.util.List;
   
   import org.apache.maven.project.MavenProject;
   
   /**
    * unique global list of deploy requests which are to be executed at the end of a multimodule project
    * 
    * 
    */
   public class DeployRequestList implements Serializable {
   	
   	private List<DeployRequest> list;
   	
   	public DeployRequestList(Integer initialListSize) {
   		list = new ArrayList<DeployRequest>(initialListSize);
   	}
   	
   	public DeployRequestList(List<DeployRequest> deployRequests) {
   		this.list = deployRequests;
   	}
   
   	public List<DeployRequest> getList() {
   		return list;
   	}
   
   	public String serialize() {
   		ByteArrayOutputStream baos = new ByteArrayOutputStream();
   		XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(baos));
   		encoder.writeObject(getList().size());
   		for (DeployRequest request : getList()) {
   			if (request == null) {
   				encoder.writeObject(null);
   			} else {
   				request.serializeIn(encoder);
   			}
   		}
   		encoder.close();
   		String result = new String(baos.toByteArray(), StandardCharsets.UTF_8);
   		return result;
   	}
   	
   	public static DeployRequestList deserialize(String serializedDeployRequestList, List<MavenProject> reactorProjects) {
   		ByteArrayInputStream bais = new ByteArrayInputStream(serializedDeployRequestList.getBytes(StandardCharsets.UTF_8));
   		
   		XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(bais));
   		Integer listSize = (Integer) decoder.readObject();
   		
   		DeployRequestList result = new DeployRequestList(listSize);
   		for (int i=0; i < listSize; i++) {
   			String projectFile = (String) decoder.readObject();
   			if (projectFile == null) {
   				result.getList().add(null);
   			} else {
   				result.getList().add(DeployRequest.deserialize(decoder, reactorProjects, projectFile));
   			}
   		}
   
   		decoder.close();
   	    
   	    return result;
   	}
   	
   }
   
   And add serialize/deserialize functions to DeployRequest:
   
   public void serializeIn(XMLEncoder encoder) {
   		encoder.writeObject(getProject().getFile().getAbsolutePath());
   	    encoder.writeObject(updateReleaseInfo);
   	    encoder.writeObject(getRetryFailedDeploymentCount());
   	    encoder.writeObject(getAltDeploymentRepository());
   	    encoder.writeObject(getAltSnapshotDeploymentRepository());
   	    encoder.writeObject(getAltReleaseDeploymentRepository());
   	}
   
   	public static DeployRequest deserialize(XMLDecoder decoder, List<MavenProject> reactorProjects,
   			String projectFile) {
   		MavenProject project = null;
   		for (MavenProject reactorProject : reactorProjects) {
   			if (projectFile.equals(reactorProject.getFile().getAbsolutePath())) {
   				project = reactorProject;
   				break;
   			}
   		}
   		if (project==null) {
   			throw new RuntimeException("Project for file '" + projectFile + "' could not be found within reactorprojects.");
   		}
   		
   		boolean read_isUpdateReleaseInfo = (Boolean) decoder.readObject();
   		int read_retryFailedDeploymentCount = (Integer) decoder.readObject();
   		String read_altDeploymentRepository = (String) decoder.readObject();
   		String read_altSnapshotDeploymentRepository = (String) decoder.readObject();
   		String read_altReleaseDeploymentRepository = (String) decoder.readObject();
   		
   		return new DeployRequest().setProject( project ).setUpdateReleaseInfo( read_isUpdateReleaseInfo ).setRetryFailedDeploymentCount( read_retryFailedDeploymentCount ).setAltReleaseDeploymentRepository( read_altReleaseDeploymentRepository ).setAltSnapshotDeploymentRepository( read_altSnapshotDeploymentRepository ).setAltDeploymentRepository( read_altDeploymentRepository );
   	}
   
   Then you can easily serialize the list into the property string. I don't think Maven Core will change its concept of different class loaders. So to hang up shared stuff in a shared variable is the way to go.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services