4339 |
07 Feb 17 |
nicklas |
1 |
package net.sf.basedb.reggie.plugins.release; |
4339 |
07 Feb 17 |
nicklas |
2 |
|
4339 |
07 Feb 17 |
nicklas |
3 |
import java.io.Closeable; |
4339 |
07 Feb 17 |
nicklas |
4 |
|
6962 |
19 Dec 22 |
nicklas |
5 |
import net.sf.basedb.core.ProgressReporter; |
4339 |
07 Feb 17 |
nicklas |
6 |
import net.sf.basedb.core.plugin.ExportOutputStream; |
4339 |
07 Feb 17 |
nicklas |
7 |
|
4339 |
07 Feb 17 |
nicklas |
8 |
/** |
4339 |
07 Feb 17 |
nicklas |
Abstract base class for an output location. Implementations |
4339 |
07 Feb 17 |
nicklas |
should provide ExportOutputStream:s that writes file data to |
4339 |
07 Feb 17 |
nicklas |
a specified file within the location. |
4339 |
07 Feb 17 |
nicklas |
12 |
|
4339 |
07 Feb 17 |
nicklas |
@author nicklas |
4339 |
07 Feb 17 |
nicklas |
@since 4.10 |
4339 |
07 Feb 17 |
nicklas |
15 |
*/ |
4339 |
07 Feb 17 |
nicklas |
16 |
public abstract class OutputLocation |
4339 |
07 Feb 17 |
nicklas |
17 |
implements Closeable |
4339 |
07 Feb 17 |
nicklas |
18 |
{ |
4339 |
07 Feb 17 |
nicklas |
19 |
|
4339 |
07 Feb 17 |
nicklas |
20 |
private boolean compress; |
4339 |
07 Feb 17 |
nicklas |
21 |
private boolean overwrite; |
4339 |
07 Feb 17 |
nicklas |
22 |
|
4339 |
07 Feb 17 |
nicklas |
23 |
protected OutputLocation() |
4339 |
07 Feb 17 |
nicklas |
24 |
{} |
4339 |
07 Feb 17 |
nicklas |
25 |
|
4339 |
07 Feb 17 |
nicklas |
26 |
/** |
4345 |
09 Feb 17 |
nicklas |
TRUE to compress output files (if supported by |
4345 |
09 Feb 17 |
nicklas |
the actual implementation). |
4339 |
07 Feb 17 |
nicklas |
29 |
*/ |
4339 |
07 Feb 17 |
nicklas |
30 |
public boolean getCompress() |
4339 |
07 Feb 17 |
nicklas |
31 |
{ |
4339 |
07 Feb 17 |
nicklas |
32 |
return compress; |
4339 |
07 Feb 17 |
nicklas |
33 |
} |
4339 |
07 Feb 17 |
nicklas |
34 |
public void setCompress(boolean compress) |
4339 |
07 Feb 17 |
nicklas |
35 |
{ |
4339 |
07 Feb 17 |
nicklas |
36 |
this.compress = compress; |
4339 |
07 Feb 17 |
nicklas |
37 |
} |
4339 |
07 Feb 17 |
nicklas |
38 |
|
4339 |
07 Feb 17 |
nicklas |
39 |
/** |
4339 |
07 Feb 17 |
nicklas |
TRUE to overwrite existing files. |
4339 |
07 Feb 17 |
nicklas |
41 |
*/ |
4339 |
07 Feb 17 |
nicklas |
42 |
public boolean getOverwrite() |
4339 |
07 Feb 17 |
nicklas |
43 |
{ |
4339 |
07 Feb 17 |
nicklas |
44 |
return overwrite; |
4339 |
07 Feb 17 |
nicklas |
45 |
} |
4339 |
07 Feb 17 |
nicklas |
46 |
public void setOverwrite(boolean overwrite) |
4339 |
07 Feb 17 |
nicklas |
47 |
{ |
4339 |
07 Feb 17 |
nicklas |
48 |
this.overwrite = overwrite; |
4339 |
07 Feb 17 |
nicklas |
49 |
} |
4339 |
07 Feb 17 |
nicklas |
50 |
|
4339 |
07 Feb 17 |
nicklas |
51 |
@Override |
4339 |
07 Feb 17 |
nicklas |
52 |
public void close() |
4339 |
07 Feb 17 |
nicklas |
53 |
{} |
4339 |
07 Feb 17 |
nicklas |
54 |
|
4339 |
07 Feb 17 |
nicklas |
55 |
/** |
6962 |
19 Dec 22 |
nicklas |
Initialize the output location with information about files |
6962 |
19 Dec 22 |
nicklas |
that exists in previous releases. If a progress reporter |
6962 |
19 Dec 22 |
nicklas |
is given it should be used to report progress between ~1-14% |
6962 |
19 Dec 22 |
nicklas |
@since 4.42 |
6962 |
19 Dec 22 |
nicklas |
60 |
*/ |
6962 |
19 Dec 22 |
nicklas |
61 |
public void init(ProgressReporter progress) |
6962 |
19 Dec 22 |
nicklas |
62 |
{} |
6962 |
19 Dec 22 |
nicklas |
63 |
|
6962 |
19 Dec 22 |
nicklas |
64 |
/** |
4339 |
07 Feb 17 |
nicklas |
Get a stream writing to the given path. The path is |
4339 |
07 Feb 17 |
nicklas |
typically expressed as an absolute path, but implementations |
4339 |
07 Feb 17 |
nicklas |
usually evaluates this within a given root path. |
4339 |
07 Feb 17 |
nicklas |
68 |
|
4339 |
07 Feb 17 |
nicklas |
@param path The path to the file |
4427 |
27 Mar 17 |
nicklas |
@param executable TRUE to make this file executable |
4345 |
09 Feb 17 |
nicklas |
@return An export output stream |
4339 |
07 Feb 17 |
nicklas |
72 |
*/ |
4427 |
27 Mar 17 |
nicklas |
73 |
public abstract ExportOutputStream getOutputStream(String path, boolean executable); |
4421 |
24 Mar 17 |
nicklas |
74 |
|
4427 |
27 Mar 17 |
nicklas |
75 |
|
4421 |
24 Mar 17 |
nicklas |
76 |
/** |
4421 |
24 Mar 17 |
nicklas |
Get the path to the top root directort that contains |
4421 |
24 Mar 17 |
nicklas |
all releases. |
4421 |
24 Mar 17 |
nicklas |
79 |
*/ |
4421 |
24 Mar 17 |
nicklas |
80 |
public abstract String getRootPath(); |
4421 |
24 Mar 17 |
nicklas |
81 |
|
4421 |
24 Mar 17 |
nicklas |
82 |
/** |
4421 |
24 Mar 17 |
nicklas |
Get the path to the topmost directory for the current release. |
4421 |
24 Mar 17 |
nicklas |
84 |
*/ |
4421 |
24 Mar 17 |
nicklas |
85 |
public abstract String getReleasePath(); |
4421 |
24 Mar 17 |
nicklas |
86 |
|
4421 |
24 Mar 17 |
nicklas |
87 |
/** |
4421 |
24 Mar 17 |
nicklas |
Find the release version of a file that may exist in some previous release. |
4421 |
24 Mar 17 |
nicklas |
Given a file structure like: |
4421 |
24 Mar 17 |
nicklas |
90 |
|
4421 |
24 Mar 17 |
nicklas |
root/ |
4421 |
24 Mar 17 |
nicklas |
1.1/ |
4421 |
24 Mar 17 |
nicklas |
/S00001/r.lib/foobar.txt |
4421 |
24 Mar 17 |
nicklas |
94 |
|
4421 |
24 Mar 17 |
nicklas |
we search for '/S00001/r.lib/foobar.txt' and get the answer '1.1'. |
4421 |
24 Mar 17 |
nicklas |
96 |
|
4421 |
24 Mar 17 |
nicklas |
@param path The path to the file relative any release directory. |
4421 |
24 Mar 17 |
nicklas |
98 |
|
4421 |
24 Mar 17 |
nicklas |
@return The release version which holds the file or null if not found |
4421 |
24 Mar 17 |
nicklas |
100 |
*/ |
4421 |
24 Mar 17 |
nicklas |
101 |
public abstract String findReleasedFile(String path); |
4421 |
24 Mar 17 |
nicklas |
102 |
|
4421 |
24 Mar 17 |
nicklas |
103 |
/** |
4421 |
24 Mar 17 |
nicklas |
Combine path elements and make sure that a single path |
4421 |
24 Mar 17 |
nicklas |
separator is inserted between each element. Null and emtpy string |
4421 |
24 Mar 17 |
nicklas |
elements are ignored. |
4421 |
24 Mar 17 |
nicklas |
107 |
*/ |
4421 |
24 Mar 17 |
nicklas |
108 |
public static String makePath(String... elements) |
4421 |
24 Mar 17 |
nicklas |
109 |
{ |
4421 |
24 Mar 17 |
nicklas |
110 |
StringBuilder s = new StringBuilder(); |
4421 |
24 Mar 17 |
nicklas |
111 |
for (String p : elements) |
4421 |
24 Mar 17 |
nicklas |
112 |
{ |
4421 |
24 Mar 17 |
nicklas |
113 |
if (p == null || p.equals("")) continue; |
4421 |
24 Mar 17 |
nicklas |
114 |
|
4421 |
24 Mar 17 |
nicklas |
115 |
if (s.length() > 0) |
4421 |
24 Mar 17 |
nicklas |
116 |
{ |
4421 |
24 Mar 17 |
nicklas |
117 |
char last = s.charAt(s.length()-1); |
4421 |
24 Mar 17 |
nicklas |
118 |
char first = p.charAt(0); |
4421 |
24 Mar 17 |
nicklas |
119 |
|
4421 |
24 Mar 17 |
nicklas |
120 |
if (last == '/' && first == '/') |
4421 |
24 Mar 17 |
nicklas |
121 |
{ |
4421 |
24 Mar 17 |
nicklas |
// Remove one '/' to avoid '//' |
4421 |
24 Mar 17 |
nicklas |
123 |
p = p.substring(1); |
4421 |
24 Mar 17 |
nicklas |
124 |
} |
4421 |
24 Mar 17 |
nicklas |
125 |
else if (last != '/' && first != '/') |
4421 |
24 Mar 17 |
nicklas |
126 |
{ |
4421 |
24 Mar 17 |
nicklas |
// Insert one '/' |
4421 |
24 Mar 17 |
nicklas |
128 |
s.append('/'); |
4421 |
24 Mar 17 |
nicklas |
129 |
} |
4421 |
24 Mar 17 |
nicklas |
130 |
} |
4421 |
24 Mar 17 |
nicklas |
131 |
s.append(p); |
4421 |
24 Mar 17 |
nicklas |
132 |
} |
4421 |
24 Mar 17 |
nicklas |
133 |
return s.toString(); |
4421 |
24 Mar 17 |
nicklas |
134 |
} |
4421 |
24 Mar 17 |
nicklas |
135 |
|
4339 |
07 Feb 17 |
nicklas |
136 |
} |