Skip to content

Commit 16c51c0

Browse files
author
John Donovan
committed
fixes #14, and fixes #15
1 parent 493b45e commit 16c51c0

16 files changed

Lines changed: 189 additions & 69 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ If either tool is ran within a customer folder, then the option is inferred and
109109
`pmbuilder` and `pmextractor` can also select the platform for you! This cuts down on typos, and typing out full file names. To use this option, navigate to your customer's directory and run `pmbuilder` with the `-s` option.
110110

111111
```bash
112-
$ pmbuilder -sp
112+
$ pmbuilder -s
113113
```
114114

115115
### Using PM Builder's Import Utility

src/com/gtnexus/appxpress/cli/option/ParsedOptions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.File;
44
import java.nio.file.Path;
5-
import java.util.Collections;
65
import java.util.HashMap;
76
import java.util.Map;
87
import java.util.Set;

src/com/gtnexus/appxpress/commons/DirectoryHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ public PMProperties getPmProperties() throws AppXpressException {
9797
}
9898
return pmbProperties;
9999
}
100+
100101
}

src/com/gtnexus/appxpress/commons/file/FileService.java

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,25 @@ public List<Path> moveFiles(final Collection<File> files,
195195
return paths;
196196
}
197197

198+
public List<Path> copyFiles(final Collection<String> fileNames,
199+
final NameToPath converter, final File destination,
200+
Precondition<File> precondition) throws IOException {
201+
if (fileNames == null || destination == null) {
202+
throw new NullPointerException(
203+
"files and destination cannot be null.");
204+
}
205+
if (!destination.isDirectory()) {
206+
throw new IllegalArgumentException(
207+
"Destination must be a directory.");
208+
}
209+
List<Path> paths = new LinkedList<>();
210+
for (String file : fileNames) {
211+
paths.add(_copyFile(destination, precondition,
212+
converter.resolve(file).toFile()));
213+
}
214+
return paths;
215+
}
216+
198217
/**
199218
*
200219
* @param files
@@ -210,20 +229,38 @@ public List<Path> copyFiles(final Collection<File> files,
210229
throw new NullPointerException(
211230
"files and destination cannot be null.");
212231
}
232+
if (!destination.isDirectory()) {
233+
throw new IOException("Destination " + destination.getName()
234+
+ " is not a directory.");
235+
}
213236
if (precondition == null) {
214237
precondition = new Precondition.EmptyCondition<>();
215238
}
239+
return _copyFiles(files, destination, precondition);
240+
}
241+
242+
private List<Path> _copyFiles(final Collection<File> files,
243+
final File destination, Precondition<File> precondition)
244+
throws IOException {
216245
List<Path> paths = new LinkedList<>();
217246
for (File file : files) {
218-
if (precondition.isMet(file)) {
219-
Path p = destination.toPath().resolve(file.getName());
220-
Files.copy(file.toPath(), p,
221-
StandardCopyOption.REPLACE_EXISTING);
222-
}
247+
Path result = _copyFile(destination, precondition, file);
248+
if (result != null)
249+
paths.add(result);
223250
}
224251
return paths;
225252
}
226253

254+
private Path _copyFile(final File destination,
255+
Precondition<File> precondition, File file) throws IOException {
256+
if (precondition.isMet(file)) {
257+
Path p = destination.toPath().resolve(file.getName());
258+
return Files.copy(file.toPath(), p,
259+
StandardCopyOption.REPLACE_EXISTING);
260+
}
261+
return null;
262+
}
263+
227264
/**
228265
*
229266
* @param sourceDir
@@ -246,13 +283,13 @@ public Path copyDirectory(File sourceDir, File destination)
246283
public Path copyDirectory(Path source, Path destination) throws IOException {
247284
if (!Files.exists(source)) {
248285
throw new IOException("Cannot copy directory tree from source: "
249-
+ source.toString()
250-
+ ". Source directory does not exist.");
286+
+ source.toString() + ". Source directory does not exist.");
251287
}
252-
if(destination.startsWith(source)) {
253-
throw new IllegalArgumentException("Cannot copy directory structure into subdirectory of itself.");
288+
if (destination.startsWith(source)) {
289+
throw new IllegalArgumentException(
290+
"Cannot copy directory structure into subdirectory of itself.");
254291
}
255-
if(!Files.exists(destination)) {
292+
if (!Files.exists(destination)) {
256293
Files.createDirectories(destination);
257294
}
258295
CopyDirVisitor visitor = new CopyDirVisitor(source, destination);
@@ -277,11 +314,10 @@ public boolean isFileType(final File file, final String extension) {
277314
public void emptyDir(final File root) throws IOException {
278315
emptyDir(root, false);
279316
}
280-
317+
281318
public void emptyDir(final Path root) throws IOException {
282319
emptyDir(root, false);
283320
}
284-
285321

286322
/**
287323
*
@@ -293,11 +329,10 @@ public void emptyDir(final File root, boolean deleteRoot)
293329
throws IOException {
294330
emptyDir(root.toPath(), deleteRoot);
295331
}
296-
332+
297333
public void emptyDir(final Path root, boolean deleteRoot)
298334
throws IOException {
299-
DeleteDirVisitor visitor = new DeleteDirVisitor(root,
300-
deleteRoot);
335+
DeleteDirVisitor visitor = new DeleteDirVisitor(root, deleteRoot);
301336
Files.walkFileTree(root, visitor);
302337
}
303338

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.gtnexus.appxpress.commons.file;
2+
3+
import java.nio.file.Path;
4+
5+
public class LibResourceToPath implements NameToPath {
6+
7+
private final Path libPath;
8+
9+
public LibResourceToPath(Path libPath) {
10+
this.libPath = libPath;
11+
}
12+
13+
@Override
14+
public Path resolve(String name) {
15+
return libPath.resolve(name);
16+
}
17+
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.gtnexus.appxpress.commons.file;
2+
3+
import java.nio.file.Path;
4+
5+
public interface NameToPath {
6+
7+
public Path resolve(String name);
8+
9+
}

src/com/gtnexus/appxpress/context/AppXpressContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.gtnexus.appxpress.context;
22

3+
import static com.gtnexus.appxpress.AppXpressConstants.LIB;
4+
35
import java.io.File;
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
48
import java.util.LinkedList;
59
import java.util.List;
610
import java.util.Map;
@@ -15,6 +19,7 @@
1519
import com.gtnexus.appxpress.commons.PMProperties;
1620
import com.gtnexus.appxpress.commons.PropertiesPersister;
1721
import com.gtnexus.appxpress.commons.SimpleShutdown;
22+
import com.gtnexus.appxpress.pmbuilder.cli.BuilderOption;
1823

1924
/**
2025
*
@@ -59,6 +64,12 @@ public ApplicationInfo getApplicationInfo() {
5964
public Map<T, String> getOptMap() {
6065
return optMap;
6166
}
67+
68+
public Path getLibPath() {
69+
String ld = properties.getProperty(BuilderOption.LOCAL_DIR);
70+
Path localDir = Paths.get(ld);
71+
return localDir.getParent().resolve(LIB);
72+
}
6273

6374
public PMProperties getPMProperties() throws AppXpressException {
6475
return dHelper.getPmProperties();

src/com/gtnexus/appxpress/pmbuilder/PlatformModuleBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void build(AppXpressContext<BuilderOption> context)
7777
throws AppXpressException {
7878
attachCleanUpHook(context);
7979
PMBuilderVO vo = new PMBuilderVO(context.getOptMap());
80-
BuildPrep prep = new BuildPrep(context);
80+
BuildPrep prep = new BuildPrep(context, context.getLibPath());
8181
PlatformModuleBundler bundler = new PlatformModuleBundler(
8282
vo.getRootFile());
8383
try {

src/com/gtnexus/appxpress/pmbuilder/bundle/platform/AppXpressMapper.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import com.gtnexus.appxpress.pmbuilder.bundle.Bundler;
88
import com.gtnexus.appxpress.pmbuilder.bundle.scripts.FolderPrep;
99
import com.gtnexus.appxpress.pmbuilder.bundle.scripts.ScriptBundler;
10-
import com.gtnexus.appxpress.pmbuilder.design.CustomObjectDesignXML;
11-
import com.gtnexus.appxpress.pmbuilder.exception.PMBuilderException;
1210
import com.gtnexus.appxpress.pmextractor.gitmap.Mapper;
1311

1412
/**
@@ -44,18 +42,6 @@ public void doMapping() throws AppXpressException {
4442
}
4543
prep.prepare(root);
4644
bundler.bundle(root);
47-
xmlDesignCustomObjectScriptMatcher(root);
4845
}
4946

50-
/**
51-
* Searches through the custom object module folder and ensures that each
52-
* custom object design xml file corresponds to the correct number of custom
53-
* object scripts
54-
*/
55-
private void xmlDesignCustomObjectScriptMatcher(File rootFile)
56-
throws PMBuilderException {
57-
CustomObjectDesignXML coDes = new CustomObjectDesignXML(rootFile);
58-
coDes.ensureSoundDesign();
59-
}
60-
6147
}

src/com/gtnexus/appxpress/pmbuilder/bundle/platform/BuildPrep.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ public class BuildPrep implements Preparation<PMBuilderVO> {
2525
private final FileService fs;
2626
private final AppXpressDirResolver resolver;
2727
private final TempResourceHolder tmpHolder;
28+
private final Path libPath;
2829

29-
public BuildPrep(TempResourceHolder tmp) {
30+
public BuildPrep(TempResourceHolder tmp, Path libPath) {
3031
this.fs = new FileService();
3132
this.resolver = new AppXpressDirResolver();
3233
this.tmpHolder = tmp;
34+
this.libPath = libPath;
3335
}
3436

3537
@Override
3638
public void prepare(final PMBuilderVO vo) throws PMBuilderException {
3739
try {
3840
File tmp = createTemp(vo);
3941
vo.setWorkingDir(tmp);
40-
runImportFind(tmp);
42+
runImportFind(tmp, libPath);
4143
map(tmp);
4244
} catch (AppXpressException | IOException e) {
4345
throw new PMBuilderException(
@@ -68,9 +70,9 @@ private File createTemp(final PMBuilderVO vo) throws IOException {
6870
* Name of platform module folder
6971
* @throws AppXpressException
7072
*/
71-
private void runImportFind(File rootFile) throws AppXpressException {
73+
private void runImportFind(final File rootFile, final Path lib) throws AppXpressException {
7274
System.out.println("Gathering imports...");
73-
ImportService iScanner = new ImportService(rootFile);
75+
ImportService iScanner = new ImportService(rootFile, lib);
7476
iScanner.scanAndImport();
7577
}
7678

0 commit comments

Comments
 (0)