[Notice] Announcing the End of Demo Server [Read me]

Make yobi.home configurable
Data and configuration is read from and stores into the home directory, which is indicated by yobi.home system property. The default home direcory equals to user.dir.
@a88c1c72f400468f069e1fa1262c7d24440ef029
--- app/Global.java
+++ app/Global.java
... | ... | @@ -378,11 +378,12 @@ |
378 | 378 |
* @return the path to the directory to store configuration files |
379 | 379 |
*/ |
380 | 380 |
static Path getDirectoryPath() { |
381 |
- return Paths.get(CONFIG_DIRNAME); |
|
381 |
+ return Paths.get(Config.getYobiHome(""), CONFIG_DIRNAME); |
|
382 | 382 |
} |
383 | 383 |
|
384 | 384 |
boolean isExternal() throws IOException, URISyntaxException { |
385 |
- return !FileUtil.isSubpathOf(getPath(), getDirectoryPath()); |
|
385 |
+ return !FileUtil.isSubpathOf(getPath(), getDirectoryPath()) && |
|
386 |
+ !FileUtil.isSubpathOf(getPath(), Paths.get(Config.getYobiHome())); |
|
386 | 387 |
} |
387 | 388 |
} |
388 | 389 |
} |
--- app/controllers/ImportApp.java
+++ app/controllers/ImportApp.java
... | ... | @@ -109,7 +109,7 @@ |
109 | 109 |
|
110 | 110 |
if (!filledNewProjectForm.errors().isEmpty()) { |
111 | 111 |
List<OrganizationUser> orgUserList = OrganizationUser.findByAdmin(UserApp.currentUser().id); |
112 |
- FileUtil.rm_rf(new File(GitRepository.getGitDirectory(project))); |
|
112 |
+ FileUtil.rm_rf(GitRepository.getGitDirectory(project)); |
|
113 | 113 |
return badRequest(importing.render("title.newProject", filledNewProjectForm, orgUserList)); |
114 | 114 |
} else { |
115 | 115 |
return redirect(routes.ProjectApp.project(project.owner, project.name)); |
--- app/models/Attachment.java
+++ app/models/Attachment.java
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 |
import play.libs.Akka; |
34 | 34 |
import scala.concurrent.duration.Duration; |
35 | 35 |
import utils.AttachmentCache; |
36 |
+import utils.Config; |
|
36 | 37 |
import utils.FileUtil; |
37 | 38 |
import utils.JodaDateUtil; |
38 | 39 |
|
... | ... | @@ -277,7 +278,11 @@ |
277 | 278 |
* @return the file |
278 | 279 |
*/ |
279 | 280 |
public File getFile() { |
280 |
- return new File(uploadDirectory, this.hash); |
|
281 |
+ return new File(getUploadDirectory(), this.hash); |
|
282 |
+ } |
|
283 |
+ |
|
284 |
+ public static File getUploadDirectory() { |
|
285 |
+ return new File(utils.Config.getYobiHome(), uploadDirectory); |
|
281 | 286 |
} |
282 | 287 |
|
283 | 288 |
/** |
... | ... | @@ -300,7 +305,7 @@ |
300 | 305 |
* @return true if the file exists |
301 | 306 |
*/ |
302 | 307 |
public static boolean fileExists(String hash) { |
303 |
- return new File(uploadDirectory, hash).isFile(); |
|
308 |
+ return new File(getUploadDirectory(), hash).isFile(); |
|
304 | 309 |
} |
305 | 310 |
|
306 | 311 |
/** |
... | ... | @@ -577,7 +582,7 @@ |
577 | 582 |
|
578 | 583 |
// Create the upload directory if it doesn't exist. |
579 | 584 |
private static File createUploadDirectory() throws NotDirectoryException { |
580 |
- File uploads = new File(uploadDirectory); |
|
585 |
+ File uploads = getUploadDirectory(); |
|
581 | 586 |
uploads.mkdirs(); |
582 | 587 |
if (!uploads.isDirectory()) { |
583 | 588 |
throw new NotDirectoryException( |
--- app/playRepository/GitRepository.java
+++ app/playRepository/GitRepository.java
... | ... | @@ -133,11 +133,11 @@ |
133 | 133 |
boolean alternatesMergeRepo) { |
134 | 134 |
try { |
135 | 135 |
RepositoryBuilder repo = new RepositoryBuilder() |
136 |
- .setGitDir(new File(getGitDirectory(ownerName, projectName))); |
|
136 |
+ .setGitDir(getGitDirectory(ownerName, projectName)); |
|
137 | 137 |
|
138 | 138 |
if (alternatesMergeRepo) { |
139 |
- repo.addAlternateObjectDirectory(new File(getDirectoryForMergingObjects(ownerName, |
|
140 |
- projectName))); |
|
139 |
+ repo.addAlternateObjectDirectory(getDirectoryForMergingObjects(ownerName, |
|
140 |
+ projectName)); |
|
141 | 141 |
} |
142 | 142 |
|
143 | 143 |
return repo.build(); |
... | ... | @@ -922,7 +922,7 @@ |
922 | 922 |
* @return |
923 | 923 |
* @see #getGitDirectory(String, String) |
924 | 924 |
*/ |
925 |
- public static String getGitDirectory(Project project) { |
|
925 |
+ public static File getGitDirectory(Project project) { |
|
926 | 926 |
return getGitDirectory(project.owner, project.name); |
927 | 927 |
} |
928 | 928 |
|
... | ... | @@ -937,8 +937,7 @@ |
937 | 937 |
* @throws IOException |
938 | 938 |
*/ |
939 | 939 |
public static String getGitDirectoryURL(Project project) throws IOException { |
940 |
- String currentDirectory = new java.io.File( "." ).getCanonicalPath(); |
|
941 |
- return currentDirectory + "/" + getGitDirectory(project); |
|
940 |
+ return getGitDirectory(project).getCanonicalPath(); |
|
942 | 941 |
} |
943 | 942 |
|
944 | 943 |
/** |
... | ... | @@ -951,8 +950,16 @@ |
951 | 950 |
* @param projectName |
952 | 951 |
* @return |
953 | 952 |
*/ |
954 |
- public static String getGitDirectory(String ownerName, String projectName) { |
|
955 |
- return getRepoPrefix() + ownerName + "/" + projectName + ".git"; |
|
953 |
+ public static File getGitDirectory(String ownerName, String projectName) { |
|
954 |
+ return new File(getRootDirectory(), ownerName + "/" + projectName + ".git"); |
|
955 |
+ } |
|
956 |
+ |
|
957 |
+ private static File getRootDirectory() { |
|
958 |
+ return new File(utils.Config.getYobiHome(), getRepoPrefix()); |
|
959 |
+ } |
|
960 |
+ |
|
961 |
+ private static File getRootDirectoryForMerging() { |
|
962 |
+ return new File(utils.Config.getYobiHome(), getRepoForMergingPrefix()); |
|
956 | 963 |
} |
957 | 964 |
|
958 | 965 |
/** |
... | ... | @@ -968,20 +975,18 @@ |
968 | 975 |
* * @see <a href="https://www.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_bare_repository">bare repository</a> |
969 | 976 |
*/ |
970 | 977 |
public static void cloneRepository(String gitUrl, Project forkingProject) throws GitAPIException { |
971 |
- String directory = getGitDirectory(forkingProject); |
|
972 | 978 |
Git.cloneRepository() |
973 | 979 |
.setURI(gitUrl) |
974 |
- .setDirectory(new File(directory)) |
|
980 |
+ .setDirectory(getGitDirectory(forkingProject)) |
|
975 | 981 |
.setCloneAllBranches(true) |
976 | 982 |
.setBare(true) |
977 | 983 |
.call(); |
978 | 984 |
} |
979 | 985 |
|
980 | 986 |
public static void cloneRepository(String gitUrl, Project forkingProject, String authId, String authPw) throws GitAPIException { |
981 |
- String directory = getGitDirectory(forkingProject); |
|
982 | 987 |
Git.cloneRepository() |
983 | 988 |
.setURI(gitUrl) |
984 |
- .setDirectory(new File(directory)) |
|
989 |
+ .setDirectory(getGitDirectory(forkingProject)) |
|
985 | 990 |
.setCloneAllBranches(true) |
986 | 991 |
.setBare(true) |
987 | 992 |
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(authId, authPw)) |
... | ... | @@ -1011,12 +1016,12 @@ |
1011 | 1016 |
* @param projectName |
1012 | 1017 |
* @return |
1013 | 1018 |
*/ |
1014 |
- public static String getDirectoryForMerging(String owner, String projectName) { |
|
1015 |
- return getRepoForMergingPrefix() + owner + "/" + projectName + ".git"; |
|
1019 |
+ public static File getDirectoryForMerging(String owner, String projectName) { |
|
1020 |
+ return new File(getRootDirectoryForMerging(), owner + "/" + projectName + ".git"); |
|
1016 | 1021 |
} |
1017 | 1022 |
|
1018 |
- public static String getDirectoryForMergingObjects(String owner, String projectName) { |
|
1019 |
- return getDirectoryForMerging(owner, projectName) + "/.git/objects"; |
|
1023 |
+ public static File getDirectoryForMergingObjects(String owner, String projectName) { |
|
1024 |
+ return new File(getDirectoryForMerging(owner, projectName), ".git/objects"); |
|
1020 | 1025 |
} |
1021 | 1026 |
|
1022 | 1027 |
@SuppressWarnings("unchecked") |
... | ... | @@ -1228,12 +1233,12 @@ |
1228 | 1233 |
} |
1229 | 1234 |
|
1230 | 1235 |
public static Repository buildMergingRepository(Project project) { |
1231 |
- String workingTree = GitRepository.getDirectoryForMerging(project.owner, project.name); |
|
1236 |
+ File workingDirectory = GitRepository.getDirectoryForMerging(project.owner, project.name); |
|
1232 | 1237 |
|
1233 | 1238 |
try { |
1234 |
- File gitDir = new File(workingTree + "/.git"); |
|
1239 |
+ File gitDir = new File(workingDirectory + "/.git"); |
|
1235 | 1240 |
if(!gitDir.exists()) { |
1236 |
- return cloneRepository(project, workingTree).getRepository(); |
|
1241 |
+ return cloneRepository(project, workingDirectory).getRepository(); |
|
1237 | 1242 |
} else { |
1238 | 1243 |
return new RepositoryBuilder().setGitDir(gitDir).build(); |
1239 | 1244 |
} |
... | ... | @@ -1242,10 +1247,10 @@ |
1242 | 1247 |
} |
1243 | 1248 |
} |
1244 | 1249 |
|
1245 |
- private static Git cloneRepository(Project project, String workingTreePath) throws GitAPIException, IOException { |
|
1250 |
+ private static Git cloneRepository(Project project, File workingDirectory) throws GitAPIException, IOException { |
|
1246 | 1251 |
return Git.cloneRepository() |
1247 | 1252 |
.setURI(GitRepository.getGitDirectoryURL(project)) |
1248 |
- .setDirectory(new File(workingTreePath)) |
|
1253 |
+ .setDirectory(workingDirectory) |
|
1249 | 1254 |
.call(); |
1250 | 1255 |
} |
1251 | 1256 |
|
... | ... | @@ -1859,10 +1864,10 @@ |
1859 | 1864 |
WindowCacheConfig config = new WindowCacheConfig(); |
1860 | 1865 |
config.install(); |
1861 | 1866 |
|
1862 |
- File srcGitDirectory = new File(getGitDirectory(srcProjectOwner, srcProjectName)); |
|
1863 |
- File destGitDirectory = new File(getGitDirectory(desrProjectOwner, destProjectName)); |
|
1864 |
- File srcGitDirectoryForMerging = new File(getDirectoryForMerging(srcProjectOwner, srcProjectName)); |
|
1865 |
- File destGitDirectoryForMerging = new File(getDirectoryForMerging(desrProjectOwner, destProjectName)); |
|
1867 |
+ File srcGitDirectory = getGitDirectory(srcProjectOwner, srcProjectName); |
|
1868 |
+ File destGitDirectory = getGitDirectory(desrProjectOwner, destProjectName); |
|
1869 |
+ File srcGitDirectoryForMerging = getDirectoryForMerging(srcProjectOwner, srcProjectName); |
|
1870 |
+ File destGitDirectoryForMerging = getDirectoryForMerging(desrProjectOwner, destProjectName); |
|
1866 | 1871 |
srcGitDirectory.setWritable(true); |
1867 | 1872 |
srcGitDirectoryForMerging.setWritable(true); |
1868 | 1873 |
|
--- app/playRepository/RepositoryService.java
+++ app/playRepository/RepositoryService.java
... | ... | @@ -36,6 +36,7 @@ |
36 | 36 |
import play.mvc.Http.Request; |
37 | 37 |
import play.mvc.Http.Response; |
38 | 38 |
import playRepository.hooks.*; |
39 |
+import utils.Config; |
|
39 | 40 |
|
40 | 41 |
import javax.servlet.ServletConfig; |
41 | 42 |
import javax.servlet.ServletContext; |
... | ... | @@ -148,7 +149,7 @@ |
148 | 149 |
@Override |
149 | 150 |
public String getInitParameter(String name) { |
150 | 151 |
if (name.equals("SVNParentPath")) { |
151 |
- return new File(SVNRepository.getRepoPrefix() + userName + "/").getAbsolutePath(); |
|
152 |
+ return new File(SVNRepository.getRootDirectory(), userName + "/").getAbsolutePath(); |
|
152 | 153 |
} else { |
153 | 154 |
return play.Configuration.root().getString("application." + name); |
154 | 155 |
} |
--- app/playRepository/SVNRepository.java
+++ app/playRepository/SVNRepository.java
... | ... | @@ -201,14 +201,12 @@ |
201 | 201 |
|
202 | 202 |
@Override |
203 | 203 |
public void create() throws SVNException { |
204 |
- String svnPath = new File(SVNRepository.getRepoPrefix() + ownerName + "/" + projectName) |
|
205 |
- .getAbsolutePath(); |
|
206 |
- SVNRepositoryFactory.createLocalRepository(new File(svnPath), true, false); |
|
204 |
+ SVNRepositoryFactory.createLocalRepository(getDirectory(), true, false); |
|
207 | 205 |
} |
208 | 206 |
|
209 | 207 |
@Override |
210 | 208 |
public void delete() throws Exception { |
211 |
- FileUtil.rm_rf(new File(getRepoPrefix() + ownerName + "/" + projectName)); |
|
209 |
+ FileUtil.rm_rf(getDirectory()); |
|
212 | 210 |
} |
213 | 211 |
|
214 | 212 |
@Override |
... | ... | @@ -224,7 +222,7 @@ |
224 | 222 |
|
225 | 223 |
private String getPatch(long revA, long revB) throws SVNException, UnsupportedEncodingException { |
226 | 224 |
// Prepare required arguments. |
227 |
- SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName)); |
|
225 |
+ SVNURL svnURL = SVNURL.fromFile(getDirectory()); |
|
228 | 226 |
|
229 | 227 |
// Get diffClient. |
230 | 228 |
SVNClientManager clientManager = SVNClientManager.newInstance(); |
... | ... | @@ -253,7 +251,7 @@ |
253 | 251 |
public List<Commit> getHistory(int page, int limit, String until, String path) throws |
254 | 252 |
IOException, GitAPIException, SVNException { |
255 | 253 |
// Get the repository |
256 |
- SVNURL svnURL = SVNURL.fromFile(new File(repoPrefix + ownerName + "/" + projectName)); |
|
254 |
+ SVNURL svnURL = SVNURL.fromFile(getDirectory()); |
|
257 | 255 |
org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL); |
258 | 256 |
|
259 | 257 |
// path to get log |
... | ... | @@ -287,7 +285,7 @@ |
287 | 285 |
public Commit getCommit(String revNumber) throws IOException, SVNException { |
288 | 286 |
long rev = Integer.parseInt(revNumber); |
289 | 287 |
String[] paths = {"/"}; |
290 |
- SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName)); |
|
288 |
+ SVNURL svnURL = SVNURL.fromFile(getDirectory()); |
|
291 | 289 |
org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL); |
292 | 290 |
|
293 | 291 |
for(Object entry : repository.log(paths, null, rev, rev, false, false)) { |
... | ... | @@ -326,8 +324,7 @@ |
326 | 324 |
} |
327 | 325 |
|
328 | 326 |
private org.tmatesoft.svn.core.io.SVNRepository getSVNRepository() throws SVNException { |
329 |
- SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + |
|
330 |
- projectName)); |
|
327 |
+ SVNURL svnURL = SVNURL.fromFile(getDirectory()); |
|
331 | 328 |
|
332 | 329 |
return SVNRepositoryFactory.create(svnURL); |
333 | 330 |
} |
... | ... | @@ -376,7 +373,7 @@ |
376 | 373 |
SVNURL svnURL; |
377 | 374 |
org.tmatesoft.svn.core.io.SVNRepository repository = null; |
378 | 375 |
try { |
379 |
- svnURL = SVNURL.fromFile(new File(repoPrefix + ownerName + "/" + projectName)); |
|
376 |
+ svnURL = SVNURL.fromFile(getDirectory()); |
|
380 | 377 |
repository = SVNRepositoryFactory.create(svnURL); |
381 | 378 |
return repository.getLatestRevision() == 0; |
382 | 379 |
} catch (SVNException e) { |
... | ... | @@ -389,8 +386,8 @@ |
389 | 386 |
} |
390 | 387 |
|
391 | 388 |
public boolean move(String srcProjectOwner, String srcProjectName, String desrProjectOwner, String destProjectName) { |
392 |
- File src = new File(getRepoPrefix() + srcProjectOwner + "/" + srcProjectName); |
|
393 |
- File dest = new File(getRepoPrefix() + desrProjectOwner + "/" + destProjectName); |
|
389 |
+ File src = new File(getRootDirectory(), srcProjectOwner + "/" + srcProjectName); |
|
390 |
+ File dest = new File(getRootDirectory(), desrProjectOwner + "/" + destProjectName); |
|
394 | 391 |
src.setWritable(true); |
395 | 392 |
|
396 | 393 |
try { |
... | ... | @@ -406,6 +403,10 @@ |
406 | 403 |
|
407 | 404 |
@Override |
408 | 405 |
public File getDirectory() { |
409 |
- return new File(getRepoPrefix() + ownerName + "/" + projectName); |
|
406 |
+ return new File(getRootDirectory(), ownerName + "/" + projectName); |
|
407 |
+ } |
|
408 |
+ |
|
409 |
+ public static File getRootDirectory() { |
|
410 |
+ return new File(Config.getYobiHome(), getRepoPrefix()); |
|
410 | 411 |
} |
411 | 412 |
} |
--- app/utils/Config.java
+++ app/utils/Config.java
... | ... | @@ -20,13 +20,20 @@ |
20 | 20 |
*/ |
21 | 21 |
package utils; |
22 | 22 |
|
23 |
+import com.typesafe.config.ConfigFactory; |
|
23 | 24 |
import models.SiteAdmin; |
24 | 25 |
import org.apache.commons.lang3.ObjectUtils; |
25 | 26 |
import play.Configuration; |
26 | 27 |
import play.mvc.Http; |
27 | 28 |
|
29 |
+import java.io.File; |
|
30 |
+import java.io.IOException; |
|
31 |
+import java.io.InputStream; |
|
28 | 32 |
import java.net.*; |
29 | 33 |
import java.nio.charset.Charset; |
34 |
+import java.nio.file.Files; |
|
35 |
+import java.nio.file.Path; |
|
36 |
+import java.nio.file.Paths; |
|
30 | 37 |
import java.util.Enumeration; |
31 | 38 |
|
32 | 39 |
public class Config { |
... | ... | @@ -303,4 +310,12 @@ |
303 | 310 |
public static <T> T get(Key<T> key) { |
304 | 311 |
return (T) Configuration.root().getObject(key.getName(), key.getDefault()); |
305 | 312 |
} |
313 |
+ |
|
314 |
+ public static String getYobiHome() { |
|
315 |
+ return System.getProperty("yobi.home"); |
|
316 |
+ } |
|
317 |
+ |
|
318 |
+ public static String getYobiHome(String defaultValue) { |
|
319 |
+ return System.getProperty("yobi.home", defaultValue); |
|
320 |
+ } |
|
306 | 321 |
} |
--- build.sbt
+++ build.sbt
... | ... | @@ -75,6 +75,7 @@ |
75 | 75 |
|
76 | 76 |
NativePackagerKeys.bashScriptExtraDefines += """# Added by build.sbt |
77 | 77 |
|YOBI_HOME=$(cd "$(realpath "$(dirname "$(realpath "$0")")")/.."; pwd -P) |
78 |
+ |addJava "-Dyobi.home=$YOBI_HOME" |
|
78 | 79 |
| |
79 | 80 |
|yobi_config_file="$YOBI_HOME"/conf/application.conf |
80 | 81 |
|yobi_log_config_file="$YOBI_HOME"/conf/application-logger.xml |
--- test/playRepository/GitRepositoryTest.java
+++ test/playRepository/GitRepositoryTest.java
... | ... | @@ -204,8 +204,8 @@ |
204 | 204 |
Project original = createProject(userName, projectName); |
205 | 205 |
Project fork = createProject("keesun", projectName); |
206 | 206 |
|
207 |
- support.Files.rm_rf(new File(GitRepository.getGitDirectory(original))); |
|
208 |
- support.Files.rm_rf(new File(GitRepository.getGitDirectory(fork))); |
|
207 |
+ support.Files.rm_rf(GitRepository.getGitDirectory(original)); |
|
208 |
+ support.Files.rm_rf(GitRepository.getGitDirectory(fork)); |
|
209 | 209 |
|
210 | 210 |
GitRepository fromRepo = new GitRepository(userName, projectName); |
211 | 211 |
fromRepo.create(); |
... | ... | @@ -215,7 +215,7 @@ |
215 | 215 |
GitRepository.cloneRepository(gitUrl, fork); |
216 | 216 |
|
217 | 217 |
// Then |
218 |
- File file = new File(GitRepository.getGitDirectory(fork)); |
|
218 |
+ File file = GitRepository.getGitDirectory(fork); |
|
219 | 219 |
assertThat(file.exists()).isTrue(); |
220 | 220 |
} |
221 | 221 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?