-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task #1189 AutoCheckout implemented using server plug-in
- Loading branch information
1 parent
da48e94
commit 3a78b82
Showing
6 changed files
with
727 additions
and
312 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
de.dlr.sc.virsat.server/src/de/dlr/sc/virsat/server/util/AutoCheckout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
de.dlr.sc.virsat.server/src/de/dlr/sc/virsat/server/util/AutoCheckoutStartup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.