Skip to content

Commit

Permalink
Merge pull request #39 from Fgerthoffert/develop
Browse files Browse the repository at this point in the history
Added ability to build a module contained in a subdirectory
  • Loading branch information
Fgerthoffert authored Jul 10, 2020
2 parents a6ed380 + bdea51e commit 28b3063
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/commands/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export default class ManifestCreate extends Command {
id: 'ldap',
deploy: true,
},
{
type: 'build',
repository: '[email protected]:Jahia/LDAP-provider.git',
branch: 'master',
gitPath: 'some-subfolder/where/pom/is/located',
directory: '/tmp/',
id: 'ldap',
deploy: true,
},
{
type: 'asset',
fetch: 'http',
Expand Down
2 changes: 2 additions & 0 deletions src/commands/manifest/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ export default class ManifestRun extends Command {
// eslint-disable-next-line no-await-in-loop
await assetsFetch(job);
} else if (job.type === 'build') {
const gitPath = job.gitPath === undefined ? null : job.gitPath;
// eslint-disable-next-line no-await-in-loop
const builtModules = await buildModule(
job.directory,
job.id,
job.branch,
gitPath,
job.repository,
);
if (job.deploy === true) {
Expand Down
15 changes: 9 additions & 6 deletions src/components/modules/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const buildModule = async (
directory: string,
id: string,
branch: string,
gitPath: string | null,
repository: string,
) => {
const dstDir = path.join(directory, id);
Expand All @@ -36,9 +37,7 @@ const buildModule = async (
console.log('WARNING: Repository directory already exists: ' + dstDir);
} else {
console.log('Cloning git repository to: ' + dstDir);
await simpleGit()
.silent(true)
.clone(repository, dstDir);
await simpleGit().silent(true).clone(repository, dstDir);
}

const git = simpleGit(dstDir);
Expand Down Expand Up @@ -72,7 +71,10 @@ const buildModule = async (
status = await git.status();
console.log(status);

const pomXml = path.join(dstDir, 'pom.xml');
const pomXml =
gitPath === null
? path.join(dstDir, 'pom.xml')
: path.join(dstDir, gitPath, 'pom.xml');
if (!fs.existsSync(pomXml)) {
console.log('ERROR: Unable to locate pom.xml');
exit();
Expand Down Expand Up @@ -114,8 +116,9 @@ const buildModule = async (
moduleVersion = pomObj.project.version[0];
}

const mvnDir = gitPath === null ? dstDir : path.join(dstDir, gitPath);
// eslint-disable-next-line noImplicitAnyForClassMembers
const mvnProject = mvn.create({ cwd: dstDir });
const mvnProject = mvn.create({ cwd: mvnDir });
// console.log(mvnProject);
console.log('Starting build');
await mvnProject.execute(['clean', 'install'], {
Expand All @@ -125,7 +128,7 @@ const buildModule = async (
console.log('Build done');

// We blindly look for generated jar files
const jarFiles = await getFiles(dstDir, moduleVersion + '.jar');
const jarFiles = await getFiles(mvnDir, moduleVersion + '.jar');

console.log(jarFiles);
return jarFiles;
Expand Down
47 changes: 35 additions & 12 deletions src/components/search/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import { sleep } from '../../../utils';
import gqlQuery from './gql';

const isIndexed = (data: any, hits: number) => {
if (data.data && data.data.jcr && data.data.jcr.searches && data.data.jcr.searches.search && data.data.jcr.searches.search.totalHits) {
if (
data.data &&
data.data.jcr &&
data.data.jcr.searches &&
data.data.jcr.searches.search &&
data.data.jcr.searches.search.totalHits
) {
const queryHits = data.data.jcr.searches.search.totalHits;
console.log('The search query returned ' + queryHits + ' hits');
console.log('The search query returned ' + queryHits + ' hits');
if (Number.parseInt(queryHits, 10) >= hits) {
return true;
}
Expand All @@ -35,22 +41,33 @@ const checkHits = async (
(timeout !== undefined && timeSinceStart < timeout)
) {
try {
// eslint-disable-next-line no-await-in-loop
// eslint-disable-next-line no-await-in-loop
console.log({ sitekey, nodetype, querystring: query });
data = await gqlClient.query({
query: gql`
${gqlQuery}
`,
variables: {sitekey, nodetype, querystring: query},
variables: { sitekey, nodetype, querystring: query },
fetchPolicy: 'no-cache',
errorPolicy: 'ignore',
});
} catch (error) {
console.log(error.message);
}
console.log(data);
console.log(data.data.errors);
const time = Math.round(timeSinceStart + performance.now());
if (isIndexed(data, hits) === false) {
await sleep(2000);
data = await checkHits(gqlClient, sitekey, nodetype, query, hits, timeout, time);
data = await checkHits(
gqlClient,
sitekey,
nodetype,
query,
hits,
timeout,
time,
);
}
}
return data;
Expand All @@ -61,16 +78,22 @@ const waitHits = async (
sitekey: string,
nodetype: string,
query: string,
hits: number,
timeout: number | undefined
) => {
hits: number,
timeout: number | undefined,
) => {
cli.action.start('Waiting for the search query to return: ' + hits + ' hits');

const data = await checkHits(gqlClient, sitekey, nodetype, query, hits, timeout, 0);
const data = await checkHits(
gqlClient,
sitekey,
nodetype,
query,
hits,
timeout,
0,
);
if (isIndexed(data, hits) === false) {
console.log(
'ERROR: Unable to validate data, most likely expired timeout',
);
console.log('ERROR: Unable to validate data, most likely expired timeout');
exit();
}
cli.action.stop();
Expand Down

0 comments on commit 28b3063

Please sign in to comment.