Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple source set directories #48

Merged
merged 1 commit into from
May 9, 2015

Conversation

advayDev1
Copy link
Contributor

Support multiple source set directories by using appropriate project properties instead of hard-coding them.

This is useful when you have multiple source-sets, such as:

sourceSets {
main {
java.srcDirs += ['otherJavaRoot/']
}
}

project.sourceSets['test'].java.srcDirs.each {
javaRoots += it.path
}
def sourcepath = javaRoots.join(':')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks good... but if you search for "src/main/java", you'll notice that the change also needs to be shared with the CycleFinderTask - line 363.

Best thing is to extract the new code to a static method on the J2objcUtils class. It'll accept "project" as a parameter and return javaRoots.join(':'). The method with then be used in both CycleFinderTask and TranslateTask. Name the method as follows:

static def sourcepathJava(Project proj) {...

…properties instead of hard-coding them.

This is useful when you have multiple source-sets, such as:

sourceSets {
  main {
    java.srcDirs += ['otherJavaRoot/']
  }
}
@advayDev1
Copy link
Contributor Author

Thanks - commit amended to d7d5081

Also for my own reference, is it intentional that you use return to return values from methods, and not just leaving the value as the last statement in the method? Want to stay consistent with your coding style.

@brunobowden
Copy link
Contributor

I didn't realize that groovy could do returns without a return statement. I'll definitely keep the style of adding "return" as I think it helps clarity for developers not as familiar with groovy. That also seems to be the consensus of StackOverflow:

http://programmers.stackexchange.com/questions/152405/when-to-write-an-explicit-return-statement-in-groovy

brunobowden added a commit that referenced this pull request May 9, 2015
Support multiple source set directories
@brunobowden brunobowden merged commit c148cd8 into j2objc-contrib:master May 9, 2015
@maxbritto
Copy link

Hello, how should we update projects that dont use sourceSets to be able to translate again. Since I've updated to latest version I have this error :

Error:FAILURE: Build failed with an exception.

* Where:
Script 'j2objc.gradle' line: 216

* What went wrong:
Execution failed for task ':rainbowapi:j2objcTranslate'.
> SourceSet with name 'main' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Thanks

@maxbritto
Copy link

I managed to make the build pass by adding this :

sourceSets {
    main {
    }
    test {
    }
}

in the build.gradle, above the dependencies section.

@advayDev1
Copy link
Contributor Author

I'll make a fix for this later today. BTW how is it that you don't use
source sets? Which plugins are you using if any?

On Tue, May 19, 2015, 8:50 AM Maxime Britto notifications@github.com
wrote:

I managed to make the build pass by adding this :

sourceSets {
main {
java.srcDirs = java.srcDirs
}
test {

}

}

in the build.gradle, above the dependencies section.


Reply to this email directly or view it on GitHub
https://github.com/brunobowden/j2objc-gradle/pull/48#issuecomment-103560226
.

@maxbritto
Copy link

I don't use any plugin, when I migrated my project from ant to gradle I created a blank Android studio project to see where it would put the sources and I followed those conventions. I also used the generated build.gradle file from the blank project and it doesn't contains any sourceSets entry. My project build without any issue without this.
BTW, the fix I mentioned above doesn't seem to work : no error is displayed but nothing is translated anymore.

@advayDev1
Copy link
Contributor Author

It seems we assume Java plugin convention in various parts of j2objc-gradle.
Let me send a PR for flags for the source directories, which when not overridden will default to java plugin conventions (which use sourcesets).

Do you have a link to a build.gradle file you are willing to let us use? It might be helpful when creating a diverse testset some day.

@advayDev1
Copy link
Contributor Author

@maxbritto , filed issue #75 to track the fix.

@maxbritto
Copy link

Thanks I'll track it there. I was wrong before, it is actually working with creating the empty sourceSets like this :

sourceSets {
    main {
    }
    test {
    }
}

I'm still exploring/discovering J2OBJC so I haven't added any test yet but for the sources they are now translated like they were before this change. Thanks for the quick answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants