use of org.eclipse.jgit.transport.RefSpec in project azure-sdk-for-java by Azure.
the class ManageLinuxWebAppSourceControl method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
// New resources
final String suffix = ".azurewebsites.net";
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
final String app4Name = SdkContext.randomResourceName("webapp4-", 20);
final String app1Url = app1Name + suffix;
final String app2Url = app2Name + suffix;
final String app3Url = app3Name + suffix;
final String app4Url = app4Name + suffix;
final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
try {
//============================================================
// Create a web app with a new app service plan
System.out.println("Creating web app " + app1Name + " in resource group " + rgName + "...");
WebApp app1 = azure.webApps().define(app1Name).withRegion(Region.US_WEST).withNewResourceGroup(rgName).withNewLinuxPlan(PricingTier.STANDARD_S1).withPublicDockerHubImage("tomcat:8-jre8").withStartUpCommand("/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"").withAppSetting("PORT", "8080").create();
System.out.println("Created web app " + app1.name());
Utils.print(app1);
//============================================================
// Deploy to app 1 through FTP
System.out.println("Deploying helloworld.war to " + app1Name + " through FTP...");
Utils.uploadFileToFtp(app1.getPublishingProfile(), "helloworld.war", ManageLinuxWebAppSourceControl.class.getResourceAsStream("/helloworld.war"));
System.out.println("Deployment helloworld.war to web app " + app1.name() + " completed");
Utils.print(app1);
// warm up
System.out.println("Warming up " + app1Url + "/helloworld...");
curl("http://" + app1Url + "/helloworld");
Thread.sleep(5000);
System.out.println("CURLing " + app1Url + "/helloworld...");
System.out.println(curl("http://" + app1Url + "/helloworld"));
//============================================================
// Create a second web app with local git source control
System.out.println("Creating another web app " + app2Name + " in resource group " + rgName + "...");
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
WebApp app2 = azure.webApps().define(app2Name).withExistingLinuxPlan(plan).withExistingResourceGroup(rgName).withPublicDockerHubImage("tomcat:8-jre8").withStartUpCommand("/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"").withAppSetting("PORT", "8080").withLocalGitSourceControl().create();
System.out.println("Created web app " + app2.name());
Utils.print(app2);
//============================================================
// Deploy to app 2 through local Git
System.out.println("Deploying a local Tomcat source to " + app2Name + " through Git...");
PublishingProfile profile = app2.getPublishingProfile();
Git git = Git.init().setDirectory(new File(ManageLinuxWebAppSourceControl.class.getResource("/azure-samples-appservice-helloworld/").getPath())).call();
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
PushCommand command = git.push();
command.setRemote(profile.gitUrl());
command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(profile.gitUsername(), profile.gitPassword()));
command.setRefSpecs(new RefSpec("master:master"));
command.setForce(true);
command.call();
System.out.println("Deployment to web app " + app2.name() + " completed");
Utils.print(app2);
// warm up
System.out.println("Warming up " + app2Url + "/helloworld...");
curl("http://" + app2Url + "/helloworld");
Thread.sleep(5000);
System.out.println("CURLing " + app2Url + "/helloworld...");
System.out.println(curl("http://" + app2Url + "/helloworld"));
//============================================================
// Create a 3rd web app with a public GitHub repo in Azure-Samples
System.out.println("Creating another web app " + app3Name + "...");
WebApp app3 = azure.webApps().define(app3Name).withExistingLinuxPlan(plan).withNewResourceGroup(rgName).withPublicDockerHubImage("tomcat:8-jre8").withStartUpCommand("/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"").withAppSetting("PORT", "8080").defineSourceControl().withPublicGitRepository("https://github.com/azure-appservice-samples/java-get-started").withBranch("master").attach().create();
System.out.println("Created web app " + app3.name());
Utils.print(app3);
// warm up
System.out.println("Warming up " + app3Url + "...");
curl("http://" + app3Url);
Thread.sleep(5000);
System.out.println("CURLing " + app3Url + "...");
System.out.println(curl("http://" + app3Url));
//============================================================
// Create a 4th web app with a personal GitHub repo and turn on continuous integration
System.out.println("Creating another web app " + app4Name + "...");
WebApp app4 = azure.webApps().define(app4Name).withExistingLinuxPlan(plan).withExistingResourceGroup(rgName).withPublicDockerHubImage("tomcat:8-jre8").withStartUpCommand("/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"").withAppSetting("PORT", "8080").create();
System.out.println("Created web app " + app4.name());
Utils.print(app4);
// warm up
System.out.println("Warming up " + app4Url + "...");
curl("http://" + app4Url);
Thread.sleep(5000);
System.out.println("CURLing " + app4Url + "...");
System.out.println(curl("http://" + app4Url));
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of org.eclipse.jgit.transport.RefSpec in project azure-sdk-for-java by Azure.
the class ManageFunctionAppSourceControl method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
// New resources
final String suffix = ".azurewebsites.net";
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
final String app4Name = SdkContext.randomResourceName("webapp4-", 20);
final String app1Url = app1Name + suffix;
final String app2Url = app2Name + suffix;
final String app3Url = app3Name + suffix;
final String app4Url = app4Name + suffix;
final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
try {
//============================================================
// Create a function app with a new app service plan
System.out.println("Creating function app " + app1Name + " in resource group " + rgName + "...");
FunctionApp app1 = azure.appServices().functionApps().define(app1Name).withRegion(Region.US_WEST).withNewResourceGroup(rgName).create();
System.out.println("Created function app " + app1.name());
Utils.print(app1);
//============================================================
// Deploy to app 1 through FTP
System.out.println("Deploying a function app to " + app1Name + " through FTP...");
Utils.uploadFileToFtp(app1.getPublishingProfile(), "host.json", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/host.json"));
Utils.uploadFileToFtp(app1.getPublishingProfile(), "square/function.json", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/square/function.json"));
Utils.uploadFileToFtp(app1.getPublishingProfile(), "square/index.js", ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/square/index.js"));
System.out.println("Deployment square app to function app " + app1.name() + " completed");
Utils.print(app1);
// warm up
System.out.println("Warming up " + app1Url + "/api/square...");
post("http://" + app1Url + "/api/square", "625");
Thread.sleep(5000);
System.out.println("CURLing " + app1Url + "/api/square...");
System.out.println("Square of 625 is " + post("http://" + app1Url + "/api/square", "625"));
//============================================================
// Create a second function app with local git source control
System.out.println("Creating another function app " + app2Name + " in resource group " + rgName + "...");
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
FunctionApp app2 = azure.appServices().functionApps().define(app2Name).withExistingAppServicePlan(plan).withExistingResourceGroup(rgName).withExistingStorageAccount(app1.storageAccount()).withLocalGitSourceControl().create();
System.out.println("Created function app " + app2.name());
Utils.print(app2);
//============================================================
// Deploy to app 2 through local Git
System.out.println("Deploying a local Tomcat source to " + app2Name + " through Git...");
PublishingProfile profile = app2.getPublishingProfile();
Git git = Git.init().setDirectory(new File(ManageFunctionAppSourceControl.class.getResource("/square-function-app/").getPath())).call();
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
PushCommand command = git.push();
command.setRemote(profile.gitUrl());
command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(profile.gitUsername(), profile.gitPassword()));
command.setRefSpecs(new RefSpec("master:master"));
command.setForce(true);
command.call();
System.out.println("Deployment to function app " + app2.name() + " completed");
Utils.print(app2);
// warm up
System.out.println("Warming up " + app2Url + "/api/square...");
post("http://" + app2Url + "/api/square", "725");
Thread.sleep(5000);
System.out.println("CURLing " + app2Url + "/api/square...");
System.out.println("Square of 725 is " + post("http://" + app2Url + "/api/square", "725"));
//============================================================
// Create a 3rd function app with a public GitHub repo in Azure-Samples
System.out.println("Creating another function app " + app3Name + "...");
FunctionApp app3 = azure.appServices().functionApps().define(app3Name).withExistingAppServicePlan(plan).withNewResourceGroup(rgName).withExistingStorageAccount(app2.storageAccount()).defineSourceControl().withPublicGitRepository("https://github.com/jianghaolu/square-function-app-sample").withBranch("master").attach().create();
System.out.println("Created function app " + app3.name());
Utils.print(app3);
// warm up
System.out.println("Warming up " + app3Url + "/api/square...");
post("http://" + app3Url + "/api/square", "825");
Thread.sleep(5000);
System.out.println("CURLing " + app3Url + "/api/square...");
System.out.println("Square of 825 is " + post("http://" + app3Url + "/api/square", "825"));
//============================================================
// Create a 4th function app with a personal GitHub repo and turn on continuous integration
System.out.println("Creating another function app " + app4Name + "...");
FunctionApp app4 = azure.appServices().functionApps().define(app4Name).withExistingAppServicePlan(plan).withExistingResourceGroup(rgName).withExistingStorageAccount(app3.storageAccount()).create();
System.out.println("Created function app " + app4.name());
Utils.print(app4);
// warm up
System.out.println("Warming up " + app4Url + "...");
curl("http://" + app4Url);
Thread.sleep(5000);
System.out.println("CURLing " + app4Url + "...");
System.out.println(curl("http://" + app4Url));
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of org.eclipse.jgit.transport.RefSpec in project che by eclipse.
the class JGitConnection method remoteUpdate.
@Override
public void remoteUpdate(RemoteUpdateParams params) throws GitException {
String remoteName = params.getName();
if (isNullOrEmpty(remoteName)) {
throw new GitException(ERROR_UPDATE_REMOTE_NAME_MISSING);
}
StoredConfig config = repository.getConfig();
Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE);
if (!remoteNames.contains(remoteName)) {
throw new GitException("Remote " + remoteName + " not found. ");
}
RemoteConfig remoteConfig;
try {
remoteConfig = new RemoteConfig(config, remoteName);
} catch (URISyntaxException e) {
throw new GitException(e.getMessage(), e);
}
List<String> branches = params.getBranches();
if (!branches.isEmpty()) {
if (!params.isAddBranches()) {
remoteConfig.setFetchRefSpecs(Collections.emptyList());
remoteConfig.setPushRefSpecs(Collections.emptyList());
} else {
// Replace wildcard refSpec if any.
remoteConfig.removeFetchRefSpec(new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*").setForceUpdate(true));
remoteConfig.removeFetchRefSpec(new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*"));
}
// Add new refSpec.
for (String branch : branches) {
remoteConfig.addFetchRefSpec(new RefSpec(Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remoteName + "/" + branch).setForceUpdate(true));
}
}
// Remove URLs first.
for (String url : params.getRemoveUrl()) {
try {
remoteConfig.removeURI(new URIish(url));
} catch (URISyntaxException e) {
LOG.debug(ERROR_UPDATE_REMOTE_REMOVE_INVALID_URL);
}
}
// Add new URLs.
for (String url : params.getAddUrl()) {
try {
remoteConfig.addURI(new URIish(url));
} catch (URISyntaxException e) {
throw new GitException("Remote url " + url + " is invalid. ");
}
}
// Remove URLs for pushing.
for (String url : params.getRemovePushUrl()) {
try {
remoteConfig.removePushURI(new URIish(url));
} catch (URISyntaxException e) {
LOG.debug(ERROR_UPDATE_REMOTE_REMOVE_INVALID_URL);
}
}
// Add URLs for pushing.
for (String url : params.getAddPushUrl()) {
try {
remoteConfig.addPushURI(new URIish(url));
} catch (URISyntaxException e) {
throw new GitException("Remote push url " + url + " is invalid. ");
}
}
remoteConfig.update(config);
try {
config.save();
} catch (IOException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.jgit.transport.RefSpec in project gitblit by gitblit.
the class GitblitManager method fork.
/*
* IGITBLIT
*/
/**
* Creates a personal fork of the specified repository. The clone is view
* restricted by default and the owner of the source repository is given
* access to the clone.
*
* @param repository
* @param user
* @return the repository model of the fork, if successful
* @throws GitBlitException
*/
@Override
public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException {
String cloneName = MessageFormat.format("{0}/{1}.git", user.getPersonalPath(), StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
String fromUrl = MessageFormat.format("file://{0}/{1}", repositoryManager.getRepositoriesFolder().getAbsolutePath(), repository.name);
// clone the repository
try {
Repository canonical = getRepository(repository.name);
File folder = new File(repositoryManager.getRepositoriesFolder(), cloneName);
CloneCommand clone = new CloneCommand();
clone.setBare(true);
// fetch branches with exclusions
Collection<Ref> branches = canonical.getRefDatabase().getRefs(Constants.R_HEADS).values();
List<String> branchesToClone = new ArrayList<String>();
for (Ref branch : branches) {
String name = branch.getName();
if (name.startsWith(Constants.R_TICKET)) {
// exclude ticket branches
continue;
}
branchesToClone.add(name);
}
clone.setBranchesToClone(branchesToClone);
clone.setURI(fromUrl);
clone.setDirectory(folder);
Git git = clone.call();
// fetch tags
FetchCommand fetch = git.fetch();
fetch.setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*"));
fetch.call();
git.getRepository().close();
} catch (Exception e) {
throw new GitBlitException(e);
}
// create a Gitblit repository model for the clone
RepositoryModel cloneModel = repository.cloneAs(cloneName);
// owner has REWIND/RW+ permissions
cloneModel.addOwner(user.username);
// is not lower than the source repository (issue-495/ticket-167)
if (repository.accessRestriction.exceeds(cloneModel.accessRestriction)) {
cloneModel.accessRestriction = repository.accessRestriction;
}
repositoryManager.updateRepositoryModel(cloneName, cloneModel, false);
// add the owner of the source repository to the clone's access list
if (!ArrayUtils.isEmpty(repository.owners)) {
for (String owner : repository.owners) {
UserModel originOwner = userManager.getUserModel(owner);
if (originOwner != null && !originOwner.canClone(cloneModel)) {
// origin owner can't yet clone fork, grant explicit clone access
originOwner.setRepositoryPermission(cloneName, AccessPermission.CLONE);
reviseUser(originOwner.username, originOwner);
}
}
}
// grant origin's user list clone permission to fork
List<String> users = repositoryManager.getRepositoryUsers(repository);
List<UserModel> cloneUsers = new ArrayList<UserModel>();
for (String name : users) {
if (!name.equalsIgnoreCase(user.username)) {
UserModel cloneUser = userManager.getUserModel(name);
if (cloneUser.canClone(repository) && !cloneUser.canClone(cloneModel)) {
// origin user can't yet clone fork, grant explicit clone access
cloneUser.setRepositoryPermission(cloneName, AccessPermission.CLONE);
}
cloneUsers.add(cloneUser);
}
}
userManager.updateUserModels(cloneUsers);
// grant origin's team list clone permission to fork
List<String> teams = repositoryManager.getRepositoryTeams(repository);
List<TeamModel> cloneTeams = new ArrayList<TeamModel>();
for (String name : teams) {
TeamModel cloneTeam = userManager.getTeamModel(name);
if (cloneTeam.canClone(repository) && !cloneTeam.canClone(cloneModel)) {
// origin team can't yet clone fork, grant explicit clone access
cloneTeam.setRepositoryPermission(cloneName, AccessPermission.CLONE);
}
cloneTeams.add(cloneTeam);
}
userManager.updateTeamModels(cloneTeams);
// add this clone to the cached model
repositoryManager.addToCachedRepositoryList(cloneModel);
if (pluginManager != null) {
for (RepositoryLifeCycleListener listener : pluginManager.getExtensions(RepositoryLifeCycleListener.class)) {
try {
listener.onFork(repository, cloneModel);
} catch (Throwable t) {
logger.error(String.format("failed to call plugin onFork %s", repository.name), t);
}
}
}
return cloneModel;
}
use of org.eclipse.jgit.transport.RefSpec in project gitblit by gitblit.
the class JGitUtils method fetchRepository.
/**
* Fetch updates from the remote repository. If refSpecs is unspecifed,
* remote heads, tags, and notes are retrieved.
*
* @param credentialsProvider
* @param repository
* @param refSpecs
* @return FetchResult
* @throws Exception
*/
public static FetchResult fetchRepository(CredentialsProvider credentialsProvider, Repository repository, RefSpec... refSpecs) throws Exception {
Git git = new Git(repository);
FetchCommand fetch = git.fetch();
List<RefSpec> specs = new ArrayList<RefSpec>();
if (refSpecs == null || refSpecs.length == 0) {
specs.add(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
specs.add(new RefSpec("+refs/tags/*:refs/tags/*"));
specs.add(new RefSpec("+refs/notes/*:refs/notes/*"));
} else {
specs.addAll(Arrays.asList(refSpecs));
}
if (credentialsProvider != null) {
fetch.setCredentialsProvider(credentialsProvider);
}
fetch.setRefSpecs(specs);
FetchResult fetchRes = fetch.call();
return fetchRes;
}
Aggregations