-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3262 from dita-ot/feature/import-project
Add support for including project files in project files
- Loading branch information
Showing
6 changed files
with
174 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* This file is part of the DITA Open Toolkit project. | ||
* | ||
* Copyright 2019 Jarno Elovirta | ||
* | ||
* See the accompanying LICENSE file for applicable license. | ||
*/ | ||
|
||
package org.dita.dost.project; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectReader; | ||
import com.google.common.collect.ImmutableSet; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class ProjectFactory { | ||
|
||
private static final ObjectReader reader = new ObjectMapper().reader().forType(Project.class); | ||
|
||
public static Project load(final URI file) throws IOException { | ||
try { | ||
return load(file, Collections.emptySet()); | ||
} catch (IOException e) { | ||
throw new IOException("Failed to read project file: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
private static Project load(final URI file, final Set<URI> processed) throws IOException { | ||
if (processed.contains(file)) { | ||
throw new RuntimeException("Recursive project file import: " + file); | ||
} | ||
final Project project = reader.readValue(file.toURL()); | ||
return resolve(project, file, ImmutableSet.<URI>builder().addAll(processed).add(file).build()); | ||
} | ||
|
||
private static Project resolve(final Project project, final URI base, final Set<URI> processed) throws IOException { | ||
if (project.includes == null || project.includes.isEmpty()) { | ||
return project; | ||
} | ||
final List<Project.Deliverable> res = project.deliverables != null | ||
? new ArrayList(project.deliverables) | ||
: new ArrayList(); | ||
if (project.includes != null) { | ||
for (final Project.ProjectRef projectRef : project.includes) { | ||
final URI href = projectRef.href.isAbsolute() ? projectRef.href : base.resolve(projectRef.href); | ||
final Project ref = load(href, processed); | ||
res.addAll(ref.deliverables); | ||
} | ||
} | ||
return new Project(res, project.includes); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"deliverables": [ | ||
{ | ||
"name": "common-name", | ||
"context": { | ||
"name": "common-Site", | ||
"id": "common-site", | ||
"inputs": { | ||
"inputs": [ | ||
{ | ||
"href": "site.ditamap" | ||
} | ||
] | ||
}, | ||
"profiles": { | ||
"ditavals": [ | ||
{ | ||
"href": "site.ditaval" | ||
} | ||
] | ||
} | ||
}, | ||
"output": "./site", | ||
"publications": { | ||
"transtype": "html5", | ||
"id": "common-sitePub", | ||
"name": "common-Site", | ||
"params": [ | ||
{ | ||
"name": "args.gen.task.lbl", | ||
"value": "YES", | ||
"href": null | ||
}, | ||
{ | ||
"name": "args.rellinks", | ||
"value": "noparent", | ||
"href": null | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"includes": [ | ||
{ | ||
"href": "recursive.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"includes": [ | ||
{ | ||
"href": "common.json" | ||
}, | ||
{ | ||
"href": "simple.json" | ||
} | ||
] | ||
} |