Skip to content

Commit

Permalink
Task #1189 AutoCheckout implemented using server plug-in
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiopelusi committed Jun 26, 2024
1 parent da48e94 commit 3a78b82
Show file tree
Hide file tree
Showing 6 changed files with 727 additions and 312 deletions.
283 changes: 275 additions & 8 deletions de.dlr.sc.virsat.javadoc.api/help/api_docs.xml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions de.dlr.sc.virsat.server/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ Require-Bundle: org.eclipse.core.runtime,
de.dlr.sc.virsat.external.lib.jersey,
javax.annotation,
jakarta.xml.bind,
javax.activation
javax.activation,
org.eclipse.ui
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ActivationPolicy: lazy
Eclipse-ExtensibleAPI: true
Export-Package: de.dlr.sc.virsat.server,
de.dlr.sc.virsat.server.jetty,
de.dlr.sc.virsat.server.resources
de.dlr.sc.virsat.server.resources,
de.dlr.sc.virsat.server.util
Automatic-Module-Name: de.dlr.sc.virsat.server
Import-Package: org.eclipse.egit.core
6 changes: 6 additions & 0 deletions de.dlr.sc.virsat.server/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
command="configFile">
</clArgs>
</extension>
<extension
point="org.eclipse.ui.startup">
<startup
class="de.dlr.sc.virsat.server.util.AutoCheckoutStartup">
</startup>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*******************************************************************************
* Copyright (c) 2020 German Aerospace Center (DLR), Simulation and Software Technology, Germany.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package de.dlr.sc.virsat.server.util;

import java.io.File;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.RepositoryUtil;

import de.dlr.sc.virsat.server.configuration.RepositoryConfiguration;
import de.dlr.sc.virsat.server.repository.ServerRepository;
import de.dlr.sc.virsat.team.VersionControlSystem;

public class AutoCheckout {

private VersionControlSystem versionControlSystemType;
private String remoteUri;
private String vcsUsername;
private String vcsPassword;
private String vcsPath;
private String projectName;

/**
* AutoCheckout Constructor
*/
public AutoCheckout() {
System.out.println(System.getenv()); // to remove
versionControlSystemType = VersionControlSystem.valueOf(System.getenv("VS_VCS_TYPE"));
remoteUri = System.getenv("VS_VCS_REMOTE_URI");
vcsUsername = System.getenv("VS_VCS_USERNAME");
vcsPassword = System.getenv("VS_VCS_PASSWORD");
vcsPath = "/vcs";
projectName = System.getenv("VS_PROJECT_NAME");
}

/**
* This method perform the autocheckout
*/
public void performAutocheckout() {
try {

System.out.println(remoteUri); // to remove
System.out.println(vcsUsername); // to remove
System.out.println(vcsPassword); // to remove
System.out.println(vcsPath); // to remove
System.out.println(projectName); // to remove

//storeCredentials();

File localRepositoryHome = new File(vcsPath);
RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration(
projectName, // gives repo_<>
projectName, // gives repo_<>/<>
remoteUri,
versionControlSystemType,
vcsUsername,
vcsPassword
);

File repositoryProjectName = new File(vcsPath + "/" + "repo_" + projectName);
if (!repositoryProjectName.exists()) {
ServerRepository serverRepository = new ServerRepository(localRepositoryHome, repositoryConfiguration);
serverRepository.checkoutRepository();
} else {
repositoryConfiguration.getProjectName();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription projectDescription = workspace.newProjectDescription(projectName);

String relativeLocalProjectPath = repositoryConfiguration.getLocalPath();
File projectInLocalRepositoryPath = new File(repositoryProjectName, relativeLocalProjectPath);
projectDescription.setLocationURI(projectInLocalRepositoryPath.toURI());

IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
project.create(projectDescription, new NullProgressMonitor());
project.open(new NullProgressMonitor());
}

if (versionControlSystemType == VersionControlSystem.GIT) {
RepositoryUtil repoUtil = RepositoryUtil.INSTANCE;
File repo = new File(repositoryProjectName.getAbsolutePath() + "/.git");
repoUtil.addConfiguredRepository(repo);
}
} catch (Exception e) {
System.out.println(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2020 German Aerospace Center (DLR), Simulation and Software Technology, Germany.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package de.dlr.sc.virsat.server.util;

import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.IStartup;

public class AutoCheckoutStartup implements IStartup {

@Override
public void earlyStartup() {

boolean autoCheckoutFlag = false;

// Check for -autocheckout flag in application arguments
String[] args = Platform.getApplicationArgs();
for (String arg : args) {
if (arg.equals("-autocheckout")) {
autoCheckoutFlag = true;
break;
}
}
if (autoCheckoutFlag) {
var autoCheckout = new AutoCheckout();
autoCheckout.performAutocheckout();
}
}
}
Loading

0 comments on commit 3a78b82

Please sign in to comment.