Skip to content

Commit e23d2c0

Browse files
committed
Merge branch '__rultor'
2 parents 713cb38 + e7021b3 commit e23d2c0

29 files changed

+890
-45
lines changed

.xcop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
--exclude=paper/**.xml
22
--exclude=src/test/resources/yml/projects/xml/**.xml
33
--exclude=src/test/resources/git/tracehub/validation/**.xml
4+
--exclude=src/test/resources/git/tracehub/validation/out/**.xml
45
--exclude=src/test/resources/yml/jobs/xml/**.xml

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ SOFTWARE.
103103
<Saxon-HE.version>12.4</Saxon-HE.version>
104104
<velocity-engine-core.version>2.3</velocity-engine-core.version>
105105
<plantuml-generator-maven-plugin.version>1.1.2</plantuml-generator-maven-plugin.version>
106+
<xembly.version>0.28.1</xembly.version>
106107
</properties>
107108
<dependencies>
108109
<dependency>
@@ -180,6 +181,11 @@ SOFTWARE.
180181
<artifactId>jcabi-xml</artifactId>
181182
<!-- version from parent POM -->
182183
</dependency>
184+
<dependency>
185+
<groupId>com.jcabi.incubator</groupId>
186+
<artifactId>xembly</artifactId>
187+
<version>${xembly.version}</version>
188+
</dependency>
183189
<dependency>
184190
<groupId>net.sf.saxon</groupId>
185191
<artifactId>Saxon-HE</artifactId>

src/main/java/git/tracehub/Backlog.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
* Backlog.
2828
*
2929
* @since 0.0.0
30-
* @todo #109:60min Use rule values to validate Job.java.
31-
* We should validate {@link Job} using values that we can get from
32-
* #rules() method. We also should think about how to resolve mixing
33-
* validations from XSL and Java.
3430
*/
3531
public interface Backlog {
3632

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2023-2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.validation;
25+
26+
import com.jcabi.xml.XSL;
27+
import git.tracehub.Job;
28+
import git.tracehub.Project;
29+
import java.io.IOException;
30+
import java.util.Map;
31+
import org.cactoos.Scalar;
32+
33+
/**
34+
* Job validation.
35+
*
36+
* @since 0.0.0
37+
*/
38+
public final class JobValidation extends ValidationEnvelope {
39+
40+
/**
41+
* Ctor.
42+
*
43+
* @param validate Job to validate
44+
* @param project Project
45+
* @param shts XSL sheets
46+
* @throws IOException if I/O fails
47+
*/
48+
public JobValidation(
49+
final Job validate,
50+
final Project project,
51+
final Scalar<Map<String, XSL>> shts
52+
) throws IOException {
53+
super(
54+
validate.label(),
55+
new RulesBound(
56+
validate,
57+
project
58+
),
59+
shts
60+
);
61+
}
62+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2023-2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.validation;
25+
26+
import java.util.List;
27+
import lombok.RequiredArgsConstructor;
28+
import org.cactoos.Scalar;
29+
import org.cactoos.Text;
30+
import org.cactoos.text.Joined;
31+
32+
/**
33+
* Joined errors.
34+
*
35+
* @since 0.0.0
36+
*/
37+
@RequiredArgsConstructor
38+
public final class JoinedErrors implements Text {
39+
40+
/**
41+
* Errors.
42+
*/
43+
private final Scalar<List<String>> errors;
44+
45+
@Override
46+
public String asString() throws Exception {
47+
return new Joined("\n", this.errors.value()).asString();
48+
}
49+
}

src/main/java/git/tracehub/validation/ProjectValidation.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,31 @@
2323
*/
2424
package git.tracehub.validation;
2525

26-
import com.jcabi.log.Logger;
2726
import com.jcabi.xml.XSL;
2827
import git.tracehub.Project;
2928
import java.util.Map;
30-
import lombok.RequiredArgsConstructor;
3129
import org.cactoos.Scalar;
32-
import org.cactoos.Text;
33-
import org.cactoos.text.Joined;
3430

3531
/**
3632
* Project (project.yml) validation.
3733
*
3834
* @since 0.0.0
3935
*/
40-
@RequiredArgsConstructor
41-
public final class ProjectValidation implements Text {
36+
public final class ProjectValidation extends ValidationEnvelope {
4237

4338
/**
44-
* Project.
39+
* Ctor.
40+
* @param project Project
41+
* @param sheets XSL sheets
4542
*/
46-
private final Project project;
47-
48-
/**
49-
* Sheets to apply.
50-
*/
51-
private final Scalar<Map<String, XSL>> sheets;
52-
53-
@Override
54-
public String asString() throws Exception {
55-
Logger.info(
56-
this,
57-
"Starting validation of project.yml in %s",
58-
this.project.identity()
43+
public ProjectValidation(
44+
final Project project,
45+
final Scalar<Map<String, XSL>> sheets
46+
) {
47+
super(
48+
project.identity(),
49+
project::asXml,
50+
sheets
5951
);
60-
return new Joined(
61-
"\n",
62-
new XsErrors(
63-
new XsApplied(
64-
this.project.asXml(),
65-
this.sheets
66-
)
67-
).value()
68-
).asString();
6952
}
7053
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2023-2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.validation;
25+
26+
import com.jcabi.xml.XML;
27+
import com.jcabi.xml.XMLDocument;
28+
import git.tracehub.Job;
29+
import git.tracehub.Project;
30+
import java.util.Map;
31+
import lombok.RequiredArgsConstructor;
32+
import org.cactoos.Scalar;
33+
import org.xembly.Directives;
34+
import org.xembly.Xembler;
35+
36+
/**
37+
* Job that contains {@code <rules>} XML node.
38+
*
39+
* @since 0.0.0
40+
*/
41+
@RequiredArgsConstructor
42+
public final class RulesBound implements Scalar<XML> {
43+
44+
/**
45+
* Job.
46+
*/
47+
private final Job job;
48+
49+
/**
50+
* Project.
51+
*/
52+
private final Project project;
53+
54+
@Override
55+
public XML value() throws Exception {
56+
final Map<String, String> rules = this.project.backlog().rules()
57+
.value();
58+
final Directives dirs = new Directives()
59+
.xpath("//LinkedHashMap");
60+
rules.forEach((rule, value) -> dirs.add(rule).set(value).up());
61+
return new XMLDocument(new Xembler(dirs).apply(this.job.asXml().node()));
62+
}
63+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2023-2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.validation;
25+
26+
import com.jcabi.log.Logger;
27+
import com.jcabi.xml.XML;
28+
import com.jcabi.xml.XSL;
29+
import java.util.Map;
30+
import lombok.RequiredArgsConstructor;
31+
import org.cactoos.Scalar;
32+
import org.cactoos.Text;
33+
34+
/**
35+
* Validation envelope.
36+
*
37+
* @since 0.0.0
38+
*/
39+
@RequiredArgsConstructor
40+
public abstract class ValidationEnvelope implements Text {
41+
42+
/**
43+
* Identity.
44+
*/
45+
private final String identity;
46+
47+
/**
48+
* Candidate.
49+
*/
50+
private final Scalar<XML> candidate;
51+
52+
/**
53+
* Sheets.
54+
*/
55+
private final Scalar<Map<String, XSL>> sheets;
56+
57+
@Override
58+
public final String asString() throws Exception {
59+
Logger.info(
60+
this,
61+
"Starting validation of job labeled '%s'",
62+
this.identity
63+
);
64+
return new JoinedErrors(
65+
new XsErrors(
66+
new XsApplied(
67+
this.candidate,
68+
this.sheets
69+
)
70+
)
71+
).asString();
72+
}
73+
}

src/main/java/git/tracehub/validation/XsApplied.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,23 @@ public final class XsApplied implements Scalar<XML> {
4747
/**
4848
* XML to validate.
4949
*/
50-
private final XML origin;
50+
private final Scalar<XML> origin;
5151

5252
/**
5353
* Sheets.
5454
*/
5555
private final Scalar<Map<String, XSL>> sheets;
5656

57+
/**
58+
* Ctor.
59+
*
60+
* @param xml XML
61+
* @param shts Sheets
62+
*/
63+
public XsApplied(final XML xml, final Scalar<Map<String, XSL>> shts) {
64+
this(() -> xml, shts);
65+
}
66+
5767
@Override
5868
public XML value() throws Exception {
5969
final Map<String, XSL> pipeline = this.sheets.value();
@@ -62,6 +72,6 @@ public XML value() throws Exception {
6272
"Applying validation, sheets activated: %s",
6373
pipeline.keySet()
6474
);
65-
return new XSLChain(pipeline.values()).transform(this.origin);
75+
return new XSLChain(pipeline.values()).transform(this.origin.value());
6676
}
6777
}

src/test/java/git/tracehub/extensions/ProjectPipeline.java renamed to src/test/java/git/tracehub/extensions/ValidationPipeline.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
import org.junit.jupiter.api.extension.ParameterResolver;
3737

3838
/**
39-
* Default Project validation pipeline.
39+
* Default validation pipeline.
4040
*
4141
* @since 0.0.0
4242
*/
43-
public final class ProjectPipeline implements ParameterResolver {
43+
public final class ValidationPipeline implements ParameterResolver {
4444
@Override
4545
public boolean supportsParameter(
4646
final ParameterContext pct,

0 commit comments

Comments
 (0)