Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Don't use secure storage anymore (password missing...:( ), run deploy…
Browse files Browse the repository at this point in the history
… in background process,
  • Loading branch information
cheleb committed Apr 23, 2012
1 parent 62bd7a2 commit 7388b78
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 99 deletions.
Expand Up @@ -14,6 +14,8 @@

public class AlfrescoPreferenceHelper {

private static final String PASSWORD = "server.reload.password";

private static final String DEPLOYMENT_MODE_WEBAPP = "Webapp";

private static final int TIMEOUT_30 = 30;
Expand Down Expand Up @@ -47,7 +49,10 @@ public class AlfrescoPreferenceHelper {

private Preferences preference;

private IProject project;

public AlfrescoPreferenceHelper(IProject project) {
this.project = project;
this.preference = getProjectPreferences(project);
}

Expand Down Expand Up @@ -76,10 +81,8 @@ public String getServerPath() {
return preference.get(SERVER_ABSOLUTE_PATH, null);
}



public String getServerReloadWebscriptURL(String serverUrl, boolean alfresco) {

if (serverUrl == null) {
return null;
}
Expand All @@ -90,8 +93,7 @@ public String getServerReloadWebscriptURL(String serverUrl, boolean alfresco) {
return serverUrl + "/page/index";
}
}



public String getServerReloadWebscriptURL() {
return getServerReloadWebscriptURL(getServerURL(), isAlfresco());

Expand All @@ -102,7 +104,7 @@ public String getServerLogin() {
}

public String getDeploymentMode() {
//TODO Implement return preference.get(DEPLOYMENT_MODE, null);
// TODO Implement return preference.get(DEPLOYMENT_MODE, null);
return DEPLOYMENT_MODE_WEBAPP;
}

Expand All @@ -120,29 +122,42 @@ public static Preferences getProjectPreferences(IProject project) {
return preferences;
}

public static void storePassword(String projectName, String password)
private static boolean isSecuredStorage() {
// TODO Auto-generated method stub
return false;
}

public void storePassword(String password)
throws StorageException {
ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node("/org/eclipse/alfresco/"
+ projectName);
node.put("password", password, true /* encrypt */);
if (isSecuredStorage()) {
ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node("/org/eclipse/alfresco/"
+ project.getName());
node.put(PASSWORD, password, true /* encrypt */);
}else {
preference.put(PASSWORD, password);
}

}

public static String getPassword(String projectName)

public String getPassword()
throws StorageException {
ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node("/org/eclipse/alfresco/"
+ projectName);
return node.get("password", null);
if(isSecuredStorage()) {
ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node("/org/eclipse/alfresco/"
+ project.getName());
return node.get(PASSWORD, null);
}else {
return preference.get(PASSWORD, null);
}

}

public boolean isAlfresco() {
return isAlfresco(getWebappName());
}



public boolean isAlfresco(String webappName) {
// TODO Auto-generated method stub
return "alfresco".equals(webappName);
Expand Down Expand Up @@ -217,8 +232,6 @@ public String getAmpLib() {
return null;
}



public boolean ignoreClasses() {
// TODO Auto-generated method stub
return true;
Expand Down Expand Up @@ -252,21 +265,20 @@ private String getSharedAbsolutePath() {
}

public void setVanillaWarAbsolutePath(String vanillaWar) {
preference.put(AlfrescoPreferenceHelper.VANILLA_WAR_ABSOLUTE_PATH, vanillaWar);

preference.put(AlfrescoPreferenceHelper.VANILLA_WAR_ABSOLUTE_PATH,
vanillaWar);

}

public String getVanillaWarAbsolutePath() {
return preference.get(AlfrescoPreferenceHelper.VANILLA_WAR_ABSOLUTE_PATH, null);
return preference.get(
AlfrescoPreferenceHelper.VANILLA_WAR_ABSOLUTE_PATH, null);
}

public int getStopTimeout() {

return preference.getInt(AlfrescoPreferenceHelper.SERVER_STOP_TIMEOUT, TIMEOUT_30);
return preference.getInt(AlfrescoPreferenceHelper.SERVER_STOP_TIMEOUT,
TIMEOUT_30);
}





}
Expand Up @@ -279,7 +279,6 @@ private static int waitProcess(final Process start,
Thread thread = new Thread() {
public void run() {
try {
monitor.subTask(name);
start.waitFor();

} catch (InterruptedException e) {
Expand Down
Expand Up @@ -60,8 +60,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
final String login = preferences.getServerLogin();
final String password;
try {
password = AlfrescoPreferenceHelper.getPassword(project
.getName());
password = preferences.getPassword();
} catch (StorageException e) {
MessageDialog.openError(window.getShell(), "Error",
e.getMessage());
Expand Down
Expand Up @@ -16,9 +16,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AMPDeployRunnable implements IRunnableWithProgress {
public class AMPDeployRunnable {

private static final int DEPLOY_N_TASK = 4;


private static final Logger LOGGER = LoggerFactory
.getLogger(AMPDeployRunnable.class);
Expand All @@ -44,16 +44,13 @@ public AMPDeployRunnable(AlfrescoDeploy alfrescoDeploy,
this.deploymentIncrementalCanceled = deploymentIncrementalCanceled;
}

@Override

public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {

if (preferences.isAlfresco()) {
monitor.beginTask("Stopping alfresco",
DEPLOY_N_TASK + preferences.getStopTimeout());
} else {
monitor.beginTask("Reloading share", DEPLOY_N_TASK);
}


monitor.worked(1);
IFile logFile = project.getFile("target/deployed.log");
if (logFile.exists()) {
try {
Expand Down Expand Up @@ -92,25 +89,25 @@ private void doDeploy(IProgressMonitor monitor)
preferences.setIncrementalDeploy(false);
preferences.flush();
}

monitor.subTask("Stopping server");
monitor.worked(1);
// monitor.subTask("Stopping server");
ServerHelper.stopServer(preferences, monitor);
if (monitor.isCanceled()) {
LOGGER.info("Canceled");
return;
}
monitor.worked(1);
monitor.subTask("Invoking build");
// monitor.subTask("Invoking build");
alfrescoDeploy.build(project, monitor);
monitor.worked(1);
if (monitor.isCanceled()) {
LOGGER.info("Canceled");
return;
}
monitor.subTask("Deploy AMP");
// monitor.subTask("Deploy AMP ");
alfrescoDeploy.deploy(project, alfrescoFileUtils, preferences, monitor);
monitor.worked(1);
monitor.subTask("Starting server");
// monitor.subTask("Starting server");
if (monitor.isCanceled()) {
LOGGER.info("Canceled");
return;
Expand Down
Expand Up @@ -16,6 +16,9 @@
import org.eclipse.alfresco.publisher.core.OperationCanceledException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
Expand All @@ -35,6 +38,8 @@

public abstract class AlfrescoDeploy implements IObjectActionDelegate {

private static final int DEPLOY_N_TASK = 4;

private static final int THREAD_SLEEP_1000 = 1000;

private static final int DEFAULT_WAR_BACKUP_FILE_KEEP_4 = 4;
Expand Down Expand Up @@ -66,19 +71,74 @@ public void run(IAction action) {
final AlfrescoFileUtils alfrescoFileUtils = new AlfrescoFileUtils(
preferences.getServerPath(), preferences.getWebappName());

try {
new ProgressMonitorDialog(shell).run(true, true,
new AMPDeployRunnable(this, alfrescoFileUtils, project,
Job job = new Job("Deploy") {

@Override
protected IStatus run(IProgressMonitor monitor) {


// monitor.beginTask("My job is working...", 100);
// for (int i = 0; i < 100; i++) {
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {} // ignore
// monitor.worked(1);
// }
// monitor.done();
// return new Status(IStatus.OK, "org.eclipse.alfresco.publisher.core", "Job finished");
//
String taskName;
int totalWork;
if (preferences.isAlfresco()) {
taskName = "Stopping alfresco";
totalWork = DEPLOY_N_TASK + preferences.getStopTimeout();
} else {
taskName="Reloading share";
totalWork=DEPLOY_N_TASK;
}
monitor.beginTask(taskName + " " + totalWork, totalWork);

try {
new AMPDeployRunnable(AlfrescoDeploy.this, alfrescoFileUtils, project,
preferences,
shoulDeactivateIncrementalDeployement()
&& preferences.isIncrementalDeploy()));
} catch (InvocationTargetException e) {
LOGGER.error(e.getLocalizedMessage(), e.getCause());
MessageDialog.openError(shell, "Error", e.getLocalizedMessage());
} catch (InterruptedException e) {
LOGGER.error(e.getLocalizedMessage(), e.getCause());
MessageDialog.openError(shell, "Error", e.getLocalizedMessage());
}
&& preferences.isIncrementalDeploy()).run(monitor);
} catch (InvocationTargetException e) {
LOGGER.error(e.getLocalizedMessage(), e.getCause());
MessageDialog.openError(shell, "Error", e.getLocalizedMessage());
} catch (InterruptedException e) {
LOGGER.error(e.getLocalizedMessage(), e.getCause());
MessageDialog.openError(shell, "Error", e.getLocalizedMessage());
}




return Status.OK_STATUS;
}
};



job.setUser(true);

job.schedule();



// try {
// new ProgressMonitorDialog(shell).run(true, true,
// new AMPDeployRunnable(this, alfrescoFileUtils, project,
// preferences,
// shoulDeactivateIncrementalDeployement()
// && preferences.isIncrementalDeploy()));
// } catch (InvocationTargetException e) {
// LOGGER.error(e.getLocalizedMessage(), e.getCause());
// MessageDialog.openError(shell, "Error", e.getLocalizedMessage());
// } catch (InterruptedException e) {
// LOGGER.error(e.getLocalizedMessage(), e.getCause());
// MessageDialog.openError(shell, "Error", e.getLocalizedMessage());
// }

}

Expand Down

0 comments on commit 7388b78

Please sign in to comment.