List of usage examples for org.eclipse.jgit.lib ObjectReader open
public ObjectLoader open(AnyObjectId objectId) throws MissingObjectException, IOException
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
private String getSourceCode(Repository repo, DiffEntry diff) throws MissingObjectException, IOException, UnsupportedEncodingException { try {/*from www . ja va2s. c om*/ ObjectReader reader = repo.newObjectReader(); byte[] bytes = reader.open(diff.getNewId().toObjectId()).getBytes(); return new String(bytes, "utf-8"); } catch (Throwable e) { return ""; } }
From source file:com.bacoder.scmtools.git.internal.CloneAndProcessDirCacheCheckout.java
License:Apache License
@Override protected boolean checkoutEntries() throws IOException { Map<String, ObjectId> updated = getUpdated(); List<String> paths = Lists.newArrayList(updated.keySet()); Collections.sort(paths);//from w w w. ja v a 2 s . co m ObjectReader objectReader = repository.getObjectDatabase().newReader(); try { for (String path : paths) { DirCacheEntry entry = dirCache.getEntry(path); if (FileMode.GITLINK.equals(entry.getRawMode())) continue; boolean isSubmoduleConfig = path.equals(Constants.DOT_GIT_MODULES); ObjectId objectId = updated.get(path); if (isSubmoduleConfig) { ObjectLoader loader = objectReader.open(objectId); byte[] data = loader.getBytes(); submodulesConfig = data; } if (processor != null) { GitEntry gitEntry = new GitEntry(repository, objectId, pathPrefix, path); try { processor.process(gitEntry); } catch (Exception e) { throw new InternalRuntimeException(e); } } } // commit the index builder - a new index is persisted if (!getBuilder().commit()) throw new IndexWriteException(); } finally { objectReader.release(); } return true; }
From source file:com.google.gerrit.server.git.ReviewNoteMerger.java
License:Eclipse Distribution License
@Override public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException { if (ours == null) { return theirs; }/* w w w .jav a 2 s . c o m*/ if (theirs == null) { return ours; } if (ours.getData().equals(theirs.getData())) { return ours; } ObjectLoader lo = reader.open(ours.getData()); byte[] sep = new byte[] { '\n' }; ObjectLoader lt = reader.open(theirs.getData()); try (ObjectStream os = lo.openStream(); ByteArrayInputStream b = new ByteArrayInputStream(sep); ObjectStream ts = lt.openStream(); UnionInputStream union = new UnionInputStream(os, b, ts)) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + sep.length + lt.getSize(), union); return new Note(ours, noteData); } }
From source file:com.googlesource.gerrit.plugins.findowners.OwnersDb.java
License:Apache License
/** Returns file content or empty string; uses Repository. */ private static String getFile(Repository repo, ObjectId id, String file, List<String> logs) { file = Util.gitRepoFilePath(file); String header = "getFile:" + file; try (RevWalk revWalk = new RevWalk(repo)) { RevTree tree = revWalk.parseCommit(id).getTree(); ObjectReader reader = revWalk.getObjectReader(); TreeWalk treeWalk = TreeWalk.forPath(reader, file, tree); if (treeWalk != null) { String content = new String(reader.open(treeWalk.getObjectId(0)).getBytes(), UTF_8); logs.add(header + ":" + content); return content; }/*from w w w. j a v a 2 s .c o m*/ logs.add(header + " (NOT FOUND)"); } catch (Exception e) { logger.atSevere().withCause(e).log("get file %s", file); logException(logs, "getFile", e); } return ""; }
From source file:com.madgag.agit.diff.LineContextDiffer.java
License:Open Source License
private byte[] open(ObjectReader reader, FileMode mode, AbbreviatedObjectId id) throws IOException { if (mode == FileMode.MISSING) return new byte[] {}; if (mode.getObjectType() != Constants.OBJ_BLOB) return new byte[] {}; if (!id.isComplete()) { Collection<ObjectId> ids = reader.resolve(id); if (ids.size() == 1) id = AbbreviatedObjectId.fromObjectId(ids.iterator().next()); else if (ids.size() == 0) throw new MissingObjectException(id, Constants.OBJ_BLOB); else//from w ww. j a va2s .c o m throw new AmbiguousObjectException(id, ids); } ObjectLoader ldr = reader.open(id.toObjectId()); return ldr.getCachedBytes(bigFileThreshold); }
From source file:com.searchcode.app.service.GitService.java
/** * Given a repository location, revision and file path will retrieve that files contents. N.B. it returns the whole * file so you MAY end up running into serious memory issues, and should be aware of this *///w w w . ja va2 s . c o m public String fetchFileRevision(String repoLocation, String revision, String filePath) throws MissingObjectException, IncorrectObjectTypeException, IOException { Repository localRepository = new FileRepository(new File(repoLocation)); ObjectId id = localRepository.resolve(revision); ObjectReader reader = localRepository.newObjectReader(); try { RevWalk walk = new RevWalk(reader); RevCommit commit = walk.parseCommit(id); RevTree tree = commit.getTree(); TreeWalk treewalk = TreeWalk.forPath(reader, filePath, tree); if (treewalk != null) { byte[] data = reader.open(treewalk.getObjectId(0)).getBytes(); return new String(data, "utf-8"); } else { return ""; } } finally { reader.close(); } }
From source file:com.thoughtworks.go.service.ConfigRepository.java
License:Apache License
private byte[] contentFromTree(RevTree tree) { try {/*from w ww.ja va 2 s .c o m*/ final ObjectReader reader = gitRepo.newObjectReader(); CanonicalTreeParser parser = new CanonicalTreeParser(); parser.reset(reader, tree); String lastPath = null; while (true) { final String path = parser.getEntryPathString(); parser = parser.next(); if (path.equals(lastPath)) { break; } lastPath = path; if (path.equals(CRUISE_CONFIG_XML)) { final ObjectId id = parser.getEntryObjectId(); final ObjectLoader loader = reader.open(id); return loader.getBytes(); } } return null; } catch (IOException e) { LOGGER.error("Could not fetch content from the config repository found at path '{}'", workingDir.getAbsolutePath(), e); throw new RuntimeException("Error while fetching content from the config repository.", e); } }
From source file:de.fau.osr.core.vcs.impl.GitVcsClient.java
License:Open Source License
/** * Reads object into a byte array.//from w w w .j a v a 2 s . c om * @param object * @return The bytes of object interpreted as utf8 String * @throws GitAPIException * @throws IOException */ byte[] readBlob(ObjectId object) throws GitAPIException, IOException { ObjectReader reader = git.getRepository().newObjectReader(); return reader.open(object).getBytes(); }
From source file:i5.las2peer.services.codeGenerationService.generators.MicroserviceGenerator.java
/** * // w w w . j a v a2 s.co m * Creates source code from a CAE microservice model and pushes it to GitHub. * * @param microservice the microservice model * @param templateRepositoryName the name of the template repository on GitHub * @param gitHubOrganization the organization that is used in the CAE * @param gitHubUser the CAE user * @param gitHubUserMail the mail of the CAE user * @param gitHubPassword the password of the CAE user * * @throws GitHubException thrown if anything goes wrong during this process. Wraps around all * other exceptions and prints their message. * */ public static void createSourceCode(Microservice microservice, String templateRepositoryName, String gitHubOrganization, String gitHubUser, String gitHubUserMail, String gitHubPassword) throws GitHubException { // variables to be closed in the final block Repository microserviceRepository = null; TreeWalk treeWalk = null; // helper variables String packageName = microservice.getResourceName().substring(0, 1).toLowerCase() + microservice.getResourceName().substring(1); // get the port: skip first 6 characters for search (http: / https:) String port = microservice.getPath().substring(microservice.getPath().indexOf(":", 6) + 1, microservice.getPath().indexOf("/", microservice.getPath().indexOf(":", 6))); // variables holding content to be modified and added to repository later String projectFile = null; BufferedImage logo = null; String readMe = null; String license = null; String buildFile = null; String startScriptWindows = null; String startScriptUnix = null; String userAgentGeneratorWindows = null; String userAgentGeneratorUnix = null; String nodeInfo = null; String antServiceProperties = null; String antUserProperties = null; String ivy = null; String ivySettings = null; String serviceProperties = null; String webConnectorConfig = null; String gitignore = null; String classpath = null; String databaseManager = null; String serviceClass = null; String serviceTest = null; String genericHttpMethod = null; String genericApiResponse = null; String genericHttpResponse = null; String genericTestCase = null; String databaseConfig = null; String databaseInstantiation = null; String serviceInvocation = null; String databaseScript = null; String genericTable = null; try { PersonIdent caeUser = new PersonIdent(gitHubUser, gitHubUserMail); String repositoryName = "microservice-" + microservice.getName().replace(" ", "-"); microserviceRepository = generateNewRepository(repositoryName, gitHubOrganization, gitHubUser, gitHubPassword); try { // now load the TreeWalk containing the template repository content treeWalk = getTemplateRepositoryContent(templateRepositoryName, gitHubOrganization); treeWalk.setFilter(PathFilter.create("backend/")); ObjectReader reader = treeWalk.getObjectReader(); // walk through the tree and retrieve the needed templates while (treeWalk.next()) { ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = reader.open(objectId); switch (treeWalk.getNameString()) { // start with the "easy" replacements, and store the other template files for later case ".project": projectFile = new String(loader.getBytes(), "UTF-8"); projectFile = projectFile.replace("$Microservice_Name$", microservice.getName()); break; case "logo_services.png": logo = ImageIO.read(loader.openStream()); break; case "README.md": readMe = new String(loader.getBytes(), "UTF-8"); readMe = readMe.replace("$Repository_Name$", repositoryName); readMe = readMe.replace("$Organization_Name$", gitHubOrganization); readMe = readMe.replace("$Microservice_Name$", microservice.getName()); break; case "LICENSE.txt": license = new String(loader.getBytes(), "UTF-8"); break; case "build.xml": buildFile = new String(loader.getBytes(), "UTF-8"); buildFile = buildFile.replace("$Microservice_Name$", microservice.getName()); break; case "start_network.bat": startScriptWindows = new String(loader.getBytes(), "UTF-8"); startScriptWindows = startScriptWindows.replace("$Resource_Name$", microservice.getResourceName()); startScriptWindows = startScriptWindows.replace("$Lower_Resource_Name$", packageName); startScriptWindows = startScriptWindows.replace("$Microservice_Version$", microservice.getVersion() + ""); break; case "start_network.sh": startScriptUnix = new String(loader.getBytes(), "UTF-8"); startScriptUnix = startScriptUnix.replace("$Resource_Name$", microservice.getResourceName()); startScriptUnix = startScriptUnix.replace("$Lower_Resource_Name$", packageName); startScriptUnix = startScriptUnix.replace("$Microservice_Version$", microservice.getVersion() + ""); break; case "start_UserAgentGenerator.bat": userAgentGeneratorWindows = new String(loader.getBytes(), "UTF-8"); break; case "start_UserAgentGenerator.sh": userAgentGeneratorUnix = new String(loader.getBytes(), "UTF-8"); break; case "nodeInfo.xml": nodeInfo = new String(loader.getBytes(), "UTF-8"); nodeInfo = nodeInfo.replace("$Developer$", microservice.getDeveloper()); nodeInfo = nodeInfo.replace("$Resource_Name$", microservice.getResourceName()); break; case "service.properties": antServiceProperties = new String(loader.getBytes(), "UTF-8"); antServiceProperties = antServiceProperties.replace("$Microservice_Version$", microservice.getVersion() + ""); antServiceProperties = antServiceProperties.replace("$Lower_Resource_Name$", packageName); antServiceProperties = antServiceProperties.replace("$Resource_Name$", microservice.getResourceName()); antServiceProperties = antServiceProperties.replace("$Microservice_Version$", microservice.getVersion() + ""); break; case "user.properties": antUserProperties = new String(loader.getBytes(), "UTF-8"); break; case "ivy.xml": ivy = new String(loader.getBytes(), "UTF-8"); // add mysql dependency only if a database exists if (microservice.getDatabase() != null) { ivy = ivy.replace("$MySQL_Dependencies$", "<dependency org=\"mysql\" name=\"mysql-connector-java\" rev=\"5.1.6\" />\n" + " <dependency org=\"org.apache.commons\" name=\"commons-pool2\" rev=\"2.2\" />\n" + " <dependency org=\"org.apache.commons\" name=\"commons-dbcp2\" rev=\"2.0\" />"); } else { ivy = ivy.replace(" $MySQL_Dependencies$\n", ""); } break; case "ivysettings.xml": ivySettings = new String(loader.getBytes(), "UTF-8"); break; case "i5.las2peer.services.servicePackage.ServiceClass.properties": serviceProperties = new String(loader.getBytes(), "UTF-8"); // if database does not exist, clear the file if (microservice.getDatabase() == null) { serviceProperties = ""; } else { serviceProperties = serviceProperties.replace("$Database_Address$", microservice.getDatabase().getAddress()); serviceProperties = serviceProperties.replace("$Database_Schema$", microservice.getDatabase().getSchema()); serviceProperties = serviceProperties.replace("$Database_User$", microservice.getDatabase().getLoginName()); serviceProperties = serviceProperties.replace("$Database_Password$", microservice.getDatabase().getLoginPassword()); } case "i5.las2peer.webConnector.WebConnector.properties": webConnectorConfig = new String(loader.getBytes(), "UTF-8"); webConnectorConfig = webConnectorConfig.replace("$HTTP_Port$", port); break; case ".gitignore": gitignore = new String(loader.getBytes(), "UTF-8"); break; case ".classpath": classpath = new String(loader.getBytes(), "UTF-8"); if (microservice.getDatabase() != null) { classpath = classpath.replace("$Database_Libraries$", "<classpathentry kind=\"lib\" path=\"lib/mysql-connector-java-5.1.6.jar\"/>\n" + " <classpathentry kind=\"lib\" path=\"lib/commons-dbcp2-2.0.jar\"/>"); } else { classpath = classpath.replace("$Database_Libraries$\n", ""); } break; case "DatabaseManager.java": if (microservice.getDatabase() != null) { databaseManager = new String(loader.getBytes(), "UTF-8"); databaseManager = databaseManager.replace("$Lower_Resource_Name$", packageName); } break; case "ServiceClass.java": serviceClass = new String(loader.getBytes(), "UTF-8"); break; case "genericHTTPMethod.txt": genericHttpMethod = new String(loader.getBytes(), "UTF-8"); break; case "genericHTTPResponse.txt": genericHttpResponse = new String(loader.getBytes(), "UTF-8"); break; case "genericApiResponse.txt": genericApiResponse = new String(loader.getBytes(), "UTF-8"); break; case "ServiceTest.java": serviceTest = new String(loader.getBytes(), "UTF-8"); break; case "genericTestMethod.txt": genericTestCase = new String(loader.getBytes(), "UTF-8"); break; case "databaseConfig.txt": databaseConfig = new String(loader.getBytes(), "UTF-8"); break; case "databaseInstantiation.txt": databaseInstantiation = new String(loader.getBytes(), "UTF-8"); break; case "genericServiceInvocation.txt": serviceInvocation = new String(loader.getBytes(), "UTF-8"); break; case "database.sql": databaseScript = new String(loader.getBytes(), "UTF-8"); break; case "genericTable.txt": genericTable = new String(loader.getBytes(), "UTF-8"); break; } } } catch (Exception e) { logger.printStackTrace(e); throw new GitHubException(e.getMessage()); } // generate service class and test String repositoryLocation = "https://github.com/" + gitHubOrganization + "/" + repositoryName; serviceClass = generateNewServiceClass(serviceClass, microservice, repositoryLocation, genericHttpMethod, genericApiResponse, genericHttpResponse, databaseConfig, databaseInstantiation, serviceInvocation); serviceTest = generateNewServiceTest(serviceTest, microservice, genericTestCase); if (microservice.getDatabase() != null) { databaseScript = generateDatabaseScript(databaseScript, genericTable, microservice); } // add files to new repository // configuration and build stuff microserviceRepository = createTextFileInRepository(microserviceRepository, "etc/ivy/", "ivy.xml", ivy); microserviceRepository = createTextFileInRepository(microserviceRepository, "etc/ivy/", "ivysettings.xml", ivySettings); microserviceRepository = createTextFileInRepository(microserviceRepository, "", "build.xml", buildFile); microserviceRepository = createTextFileInRepository(microserviceRepository, "etc/ant_configuration/", "user.properties", antUserProperties); microserviceRepository = createTextFileInRepository(microserviceRepository, "etc/ant_configuration/", "service.properties", antServiceProperties); microserviceRepository = createTextFileInRepository(microserviceRepository, "etc/", "nodeInfo.xml", nodeInfo); microserviceRepository = createTextFileInRepository(microserviceRepository, "", ".project", projectFile); microserviceRepository = createTextFileInRepository(microserviceRepository, "", ".gitignore", gitignore); microserviceRepository = createTextFileInRepository(microserviceRepository, "", ".classpath", classpath); // property files microserviceRepository = createTextFileInRepository(microserviceRepository, "etc/", "i5.las2peer.services." + packageName + "." + microservice.getResourceName() + ".properties", serviceProperties); microserviceRepository = createTextFileInRepository(microserviceRepository, "etc/", "i5.las2peer.webConnector.WebConnector.properties", webConnectorConfig); // scripts microserviceRepository = createTextFileInRepository(microserviceRepository, "bin/", "start_network.bat", startScriptWindows); microserviceRepository = createTextFileInRepository(microserviceRepository, "bin/", "start_network.sh", startScriptUnix); microserviceRepository = createTextFileInRepository(microserviceRepository, "bin/", "start_UserAgentGenerator.bat", userAgentGeneratorWindows); microserviceRepository = createTextFileInRepository(microserviceRepository, "bin/", "start_UserAgentGenerator.sh", userAgentGeneratorUnix); // doc microserviceRepository = createTextFileInRepository(microserviceRepository, "", "README.md", readMe); microserviceRepository = createTextFileInRepository(microserviceRepository, "", "LICENSE.txt", license); microserviceRepository = createImageFileInRepository(microserviceRepository, "img/", "logo.png", logo); // source code if (databaseManager != null) { microserviceRepository = createTextFileInRepository(microserviceRepository, "src/main/i5/las2peer/services/" + packageName + "/database/", "DatabaseManager.java", databaseManager); // database script (replace spaces in filename for better usability later on) microserviceRepository = createTextFileInRepository(microserviceRepository, "db/", microservice.getName().replace(" ", "_") + "_create_tables.sql", databaseScript); } microserviceRepository = createTextFileInRepository(microserviceRepository, "src/main/i5/las2peer/services/" + packageName + "/", microservice.getResourceName() + ".java", serviceClass); microserviceRepository = createTextFileInRepository(microserviceRepository, "src/test/i5/las2peer/services/" + packageName + "/", microservice.getResourceName() + "Test.java", serviceTest); // commit files try { Git.wrap(microserviceRepository).commit() .setMessage("Generated microservice version " + microservice.getVersion()) .setCommitter(caeUser).call(); } catch (Exception e) { logger.printStackTrace(e); throw new GitHubException(e.getMessage()); } // push (local) repository content to GitHub repository try { pushToRemoteRepository(microserviceRepository, gitHubUser, gitHubPassword); } catch (Exception e) { logger.printStackTrace(e); throw new GitHubException(e.getMessage()); } // close all open resources } finally { microserviceRepository.close(); treeWalk.close(); } }
From source file:i5.las2peer.services.gamificationGamifierService.GamificationGamifierService.java
License:Open Source License
@POST @Path("/repo") @Produces(MediaType.APPLICATION_JSON)// ww w .j a v a 2s. co m @ApiOperation(value = "memberLoginValidation", notes = "Simple function to validate a member login.") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Member is registered"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "User data error to be retrieved"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Cannot connect to database"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "User data error to be retrieved. Not JSON object") }) public HttpResponse updateRepository( @ApiParam(value = "Data in JSON", required = true) @ContentParam byte[] contentB) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "POST " + "gamification/gamifier/repo"); long randomLong = new Random().nextLong(); //To be able to match UserAgent userAgent = (UserAgent) getContext().getMainAgent(); // take username as default name String name = userAgent.getLoginName(); System.out.println("User name : " + name); if (name.equals("anonymous")) { return unauthorizedMessage(); } L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_9, "" + randomLong); JSONObject objResponse = new JSONObject(); String content = new String(contentB); if (content.equals(null)) { objResponse.put("message", "Cannot update repository. Cannot parse json data into string"); //L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); L2pLogger.logEvent(this, Event.AGENT_UPLOAD_FAILED, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // if(!initializeDBConnection()){ // objResponse.put("message", "Cannot connect to database"); // L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); // return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); // } JSONObject obj; String originRepositoryName; String newRepositoryName; String fileContent; String appId; String epURL; String aopScript; try { obj = (JSONObject) JSONValue.parseWithException(content); originRepositoryName = stringfromJSON(obj, "originRepositoryName"); newRepositoryName = stringfromJSON(obj, "newRepositoryName"); //fileContent = stringfromJSON(obj,"fileContent"); appId = stringfromJSON(obj, "appId"); epURL = stringfromJSON(obj, "epURL"); aopScript = stringfromJSON(obj, "aopScript"); } catch (ParseException e) { e.printStackTrace(); objResponse.put("message", "Cannot update repository. Cannot parse json data into string. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (IOException e) { e.printStackTrace(); objResponse.put("message", "Cannot update repository. Cannot parse json data into string. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // check if repo exist TreeWalk treeWalk = null; Repository newRepository = null; Repository originRepository = null; // helper variables // variables holding content to be modified and added to repository later String widget = null; try { RepositoryHelper.deleteRemoteRepository(newRepositoryName, gitHubOrganizationNewRepo, gitHubUserNewRepo, gitHubPasswordNewRepo); } catch (GitHubException e) { //e.printStackTrace(); } try { PersonIdent caeUser = new PersonIdent(gitHubUserNewRepo, gitHubUserMailNewRepo); originRepository = RepositoryHelper.getRemoteRepository(originRepositoryName, gitHubOrganizationOrigin); newRepository = RepositoryHelper.generateNewRepository(newRepositoryName, gitHubOrganizationNewRepo, gitHubUserNewRepo, gitHubPasswordNewRepo); File originDir = originRepository.getDirectory(); // now load the TreeWalk containing the origin repository content treeWalk = RepositoryHelper.getRepositoryContent(originRepositoryName, gitHubOrganizationOrigin); //System.out.println("PATH " + treeWalk.getPathString()); System.out.println("PATH2 " + originDir.getParent()); System.out.println("PATH3 " + newRepository.getDirectory().getParent()); // treeWalk.setFilter(PathFilter.create("frontend/")); ObjectReader reader = treeWalk.getObjectReader(); // walk through the tree and retrieve the needed templates while (treeWalk.next()) { ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = reader.open(objectId); switch (treeWalk.getNameString()) { case "widget.xml": widget = new String(loader.getBytes(), "UTF-8"); break; } } // replace widget.xml //widget = createWidgetCode(widget, htmlElementTemplate, yjsImports, gitHubOrganization, repositoryName, frontendComponent); widget = RepositoryHelper.appendWidget(widget, gitHubOrganizationNewRepo, newRepositoryName); RepositoryHelper.copyFolder(originRepository.getDirectory().getParentFile(), newRepository.getDirectory().getParentFile()); String aopfilestring = RepositoryHelper.readFile("../GamificationGamifierService/jsfiles/aop.pack.js", Charset.forName("UTF-8")); String oidcwidgetfilestring = RepositoryHelper .readFile("../GamificationGamifierService/jsfiles/oidc-widget.js", Charset.forName("UTF-8")); String gamifierstring = RepositoryHelper.readFile("../GamificationGamifierService/jsfiles/gamifier.js", Charset.forName("UTF-8")); gamifierstring = gamifierstring.replace("$Application_Id$", appId); gamifierstring = gamifierstring.replace("$Endpoint_URL$", epURL); gamifierstring = gamifierstring.replace("$AOP_Script$", aopScript); // add files to new repository newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "", "widget.xml", widget); newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "gamification/", "aop.pack.js", aopfilestring); newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "gamification/", "oidc-widget.js", oidcwidgetfilestring); newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "gamification/", "gamifier.js", gamifierstring); // stage file Git.wrap(newRepository).add().addFilepattern(".").call(); // commit files Git.wrap(newRepository).commit().setMessage("Generated new repo ").setCommitter(caeUser).call(); // push (local) repository content to GitHub repository "gh-pages" branch RepositoryHelper.pushToRemoteRepository(newRepository, gitHubUserNewRepo, gitHubPasswordNewRepo, "master", "gh-pages"); // close all open resources } catch (GitHubException e1) { // TODO Auto-generated catch block e1.printStackTrace(); objResponse.put("message", "Cannot update repository. Github exception. " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (IOException e1) { e1.printStackTrace(); objResponse.put("message", "Cannot update repository. Github exception. " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (Exception e) { objResponse.put("message", "Cannot update repository. Github exception. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } finally { newRepository.close(); originRepository.close(); treeWalk.close(); } objResponse.put("message", "Updated"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_10, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_22, "" + appId); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_23, "" + name); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); }